modularity: Modularity of a community structure of a graph

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/modularity.R

Description

Computes the modularity of partitioning of a graph into sub-graphs. Similar to the modularity function in the igraph package, but allows negative edge weights.

Usage

1
modularity(adj, membership, decomp = FALSE)

Arguments

adj

An adjacency matrix, which should be symmetric with zeros on the diagonal.

membership

Vector of length equal to the number of graph nodes (columns/rows of adj) indicating the cluster/sub-graph each nodes belongs to.

decomp

Logical. If TRUE, calculate the decomposition of modularity by modules and nodes. Default FALSE.

Details

The difference between this function and the function modularity in the package igraph is that this function can be used with an adjacency matrix with negative elements. This is a common case for matrices arrising from a for correlation matrix or another synchrony matrix. If the matrix is non-negative, the result of this function should be exactly the same as the result from modularity in the igraph package.

Value

modularity returns a list containing the following:

totQ

The total modularity. This is the only output if decomp=FALSE

modQ

The contribution of each module to the total modularity

nodeQ

The contribution of each node to the total modularity

Note

Adapted from code developed by Robert J. Fletcher, Jr.

Author(s)

Jonathan Walter, jonathan.walter@ku.edu; Lei Zhao, lei.zhao@cau.edu.cn; Daniel Reuman, reuman@ku.edu

References

Fletcher Jr., R.J., et al. (2013) Network modularity reveals critical scales for connectivity in ecology and evolution. Nature Communications. doi: 10.1038//ncomms3572.

Gomez S., Jensen P. & Arenas A. (2009). Analysis of community structure in networks of correlated data. Phys Rev E, 80, 016114.

Newman M.E. (2006). Finding community structure in networks using the eigenvectors of matrices. Phys Rev E, 74, 036104.

See Also

clust, cluseigen, browseVignettes("wsyn")

Examples

1
2
3
4
5
6
adj<-matrix(0, 10, 10) # create a fake adjacency matrix
adj[lower.tri(adj)]<-runif(10*9/2, -1, 1)
adj<-adj+t(adj)
colnames(adj)<-letters[1:10]
m<-cluseigen(adj)
z<-modularity(adj, m[[length(m)]], decomp=TRUE)

wsyn documentation built on Jan. 15, 2021, 3:37 p.m.