Compares observed modularity against a null model distribution to assess whether the detected community structure is statistically significant.
cluster_significance(
x,
communities,
n_random = 100,
method = c("configuration", "gnm"),
null = c("detect", "fixed"),
seed = NULL
)csig(
x,
communities,
n_random = 100,
method = c("configuration", "gnm"),
null = c("detect", "fixed"),
seed = NULL
)
A cograph_cluster_significance object with:
Modularity of the input communities
Mean modularity of random networks
Standard deviation of null modularity
Standardized score: (observed - null_mean) / null_sd
One-sided p-value (probability of observing equal or higher modularity by chance)
Vector of modularity values from null distribution
Null model method used
Which null question was asked ("detect" or "fixed")
Number of random networks generated
See cluster_significance.
Network input: adjacency matrix, igraph object, or cograph_network.
A communities object (from communities or
igraph) or a membership vector (integer vector where communities[i]
is the community of node i).
Number of random networks to generate for the null distribution. Default 100.
Null model type:
Preserves degree sequence (default). More stringent test.
Erdos-Renyi model with same number of edges. Tests against random baseline.
Which null question to answer. Default "detect":
Null is the modularity of the best partition found by community detection on each null graph. Answers "is the observed partition stronger than what community detection would recover on similar random graphs?" — the historical behavior.
Null is the modularity of the supplied
communities membership evaluated on each null graph.
Answers "does the supplied partition itself explain more structure
than it would on similar random graphs?" — the conservative test.
Random seed for reproducibility. Default NULL.
Two null models are supported. The default, null = "detect",
generates n_random random networks, runs community detection
(Louvain, with fast-greedy fallback) on each, and records the resulting
modularity. Low p-value means the observed partition beats what
detection would return on similar random graphs. null = "fixed"
instead evaluates the user-supplied membership on each null graph, so
low p-value means the partition itself is stronger than it would be on
similar random graphs — a tighter question that isolates the
partition's quality from any detector's behavior.
A significant result (low p-value) indicates that the community structure is stronger than expected by chance for networks with similar properties.
Reichardt, J., & Bornholdt, S. (2006). Statistical mechanics of community detection. Physical Review E, 74, 016110.
communities, cluster_quality
g <- igraph::make_graph("Zachary")
comm <- community_louvain(g)
sig <- cluster_significance(g, comm, n_random = 20, seed = 123)
print(sig)
if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::make_graph("Zachary")
comm <- community_louvain(g)
csig(g, comm, n_random = 20, seed = 1)
}
Run the code above in your browser using DataLab