Modularity contrasts the observed weight inside communities with the
weight the configuration model would put there, k_i k_j / 2m.
A single community containing every node scores exactly zero, however
dense the graph, because observed and expected weight then agree by
construction.
Arguments
- A
Symmetric adjacency or weight matrix.
- labels
Integer community label per node.
Value
List with Q, estimate, n_communities, n.
Details
Formula: Q = (1 / 2m) sum_ij (A_ij - k_i k_j / 2m) delta(c_i, c_j).
References
Newman, M. E. J. & Girvan, M. (2004). Finding and
evaluating community structure in networks. Physical Review E 69,
026113. doi:10.1103/PhysRevE.69.026113
.
Examples
A <- matrix(0, 6, 6); A[1:3, 1:3] <- 1; A[4:6, 4:6] <- 1; A[3, 4] <- A[4, 3] <- 1; diag(A) <- 0
Sgtmodq(A, labels = c(1, 1, 1, 2, 2, 2))$Q
#> [1] 0.3571429
Sgtmodq(A, labels = rep(1, 6))$Q # one community: exactly 0
#> [1] 1.586033e-17