View source: R/cluster-metrics.R
| cluster_significance | R Documentation |
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"),
seed = NULL
)
csig(
x,
communities,
n_random = 100,
method = c("configuration", "gnm"),
seed = NULL
)
x |
Network input: adjacency matrix, igraph object, or cograph_network. |
communities |
A communities object (from |
n_random |
Number of random networks to generate for the null distribution. Default 100. |
method |
Null model type:
|
seed |
Random seed for reproducibility. Default NULL. |
The test works by:
Computing the modularity of the provided community structure
Generating n_random random networks using the specified null model
For each random network, detecting communities with Louvain and computing modularity
Comparing the observed modularity to this null distribution
A significant result (low p-value) indicates that the community structure is stronger than expected by chance for networks with similar properties.
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
Number of random networks generated
See cluster_significance.
Reichardt, J., & Bornholdt, S. (2006). Statistical mechanics of community detection. Physical Review E, 74, 016110.
communities, cluster_quality
## Not run:
if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::make_graph("Zachary")
comm <- community_louvain(g)
# Test significance
sig <- cluster_significance(g, comm, n_random = 100, seed = 123)
print(sig)
# Configuration model (stricter test)
sig2 <- cluster_significance(g, comm, method = "configuration")
}
## End(Not run)
if (requireNamespace("igraph", quietly = TRUE)) {
g <- igraph::make_graph("Zachary")
comm <- community_louvain(g)
csig(g, comm, n_random = 20, seed = 1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.