cluster_significance: Test Significance of Community Structure

View source: R/cluster-metrics.R

cluster_significanceR Documentation

Test Significance of Community Structure

Description

Compares observed modularity against a null model distribution to assess whether the detected community structure is statistically significant.

Usage

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
)

Arguments

x

Network input: adjacency matrix, igraph object, or cograph_network.

communities

A communities object (from communities or igraph) or a membership vector (integer vector where communities[i] is the community of node i).

n_random

Number of random networks to generate for the null distribution. Default 100.

method

Null model type:

"configuration"

Preserves degree sequence (default). More stringent test.

"gnm"

Erdos-Renyi model with same number of edges. Tests against random baseline.

seed

Random seed for reproducibility. Default NULL.

Details

The test works by:

  1. Computing the modularity of the provided community structure

  2. Generating n_random random networks using the specified null model

  3. For each random network, detecting communities with Louvain and computing modularity

  4. 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.

Value

A cograph_cluster_significance object with:

observed_modularity

Modularity of the input communities

null_mean

Mean modularity of random networks

null_sd

Standard deviation of null modularity

z_score

Standardized score: (observed - null_mean) / null_sd

p_value

One-sided p-value (probability of observing equal or higher modularity by chance)

null_values

Vector of modularity values from null distribution

method

Null model method used

n_random

Number of random networks generated

See cluster_significance.

References

Reichardt, J., & Bornholdt, S. (2006). Statistical mechanics of community detection. Physical Review E, 74, 016110.

See Also

communities, cluster_quality

Examples

## 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)
}

cograph documentation built on April 1, 2026, 1:07 a.m.