| modularity {igraph} | R Documentation |
This function calculates how modular is a given division of a graph into subgraphs.
## S3 method for class 'igraph' modularity(x, membership, weights = NULL, ...) mod.matrix (graph, membership, weights = NULL)
x,graph |
The input graph. |
membership |
Numeric vector, for each vertex it gives its community. The communities are numbered from one. |
weights |
If not |
... |
Additional arguments, none currently. |
modularity calculates the modularity of a graph with respect to
the given membership vector.
The modularity of a graph with respect to some division (or vertex types) measures how good the division is, or how separated are the different vertex types from each other. It defined as
Q=1/(2m) * sum(Aij-ki*kj/(2m)delta(ci,cj),i,j),
here m is the number of edges, Aij is the element of the A adjacency matrix in row i and column j, ki is the degree of i, kj is the degree of j, ci is the type (or component) of i, cj that of j, the sum goes over all i and j pairs of vertices, and delta(x,y) is 1 if x=y and 0 otherwise.
If edge weights are given, then these are considered as the element of the A adjacency matrix, and ki is the sum of weights of adjacent edges for vertex i.
mod.matrix calculates the modularity matrix. This is a dense
matrix, and it is defined as the difference of the adjacency matrix
and the configuration model null model matrix. In other words element
M[i,j] is given as
A[i,j]-d[i]d[j]/(2m), where
A[i,j] is the (possibly weighted) adjacency matrix,
d[i] is the degree of vertex i, and m is the
number of edges (or the total weights in the graph, if it is
weighed).
For modularity a numeric scalar, the modularity score of the
given configuration.
For mod.matrix a numeic square matrix, its order is the number
of vertices in the graph.
Gabor Csardi csardi.gabor@gmail.com
MEJ Newman and M Girvan: Finding and evaluating community structure in networks. Physical Review E 69 026113, 2004.
walktrap.community,
edge.betweenness.community,
fastgreedy.community,
spinglass.community for various community detection
methods.
g <- graph.full(5) %du% graph.full(5) %du% graph.full(5) g <- add.edges(g, c(1,6, 1,11, 6, 11)) wtc <- walktrap.community(g) modularity(wtc) modularity(g, membership(wtc))