Modularity Analysis

Machine Learning
Introduced by
Newman, M. E. J. & Girvan, M.
Year
2004
Type
Community detection / graph partitioning
Family
Network science

What does it do?

Modularity analysis is a network science method, formalized by Newman and Girvan in 2004, that detects community structure by testing whether edges are concentrated within groups more than a degree-preserving random null model would predict.

It scores candidate partitions with a scalar quality index, Q, and uses an optimizer to find the partition with the highest Q. The method applies to social, biological and technological networks and does not require the number of communities to be fixed in advance.

The intuition behind the method

Imagine randomly rewiring all the edges of a network while keeping each node's degree unchanged. The result has no real community structure beyond what degrees alone produce. Modularity compares the actual edge distribution with this null model: if a partition places many more edges within its groups than the null model predicts, Q is high, which suggests genuine community structure. An optimizer searches the space of partitions for the one with the highest Q, so the groups are an output of the analysis rather than an input.

History

The modularity function was introduced by Newman and Girvan in 2004 (newmanGirvan2004), in a paper that also proposed edge-removal community detection algorithms and a measure of community strength. Newman (2006) showed that modularity can be written in terms of eigenvectors of a modularity matrix and proposed a spectral optimization algorithm. Later greedy optimizers, such as the Louvain method and its refinement, Leiden, are widely used to optimize Q on large networks.

When to use it

Use modularity analysis when your data can be represented as a graph of nodes and relations and you want cohesive subgroups without fixing their number in advance. Examples include factions in social networks, functional modules in protein-interaction networks, and topic clusters in citation networks. The formula given here is for undirected graphs, so directed or weighted data need an extended formulation. Avoid the method when the network is very small, where a few edges can dominate the partition; when edge weights carry information that a binary null model discards; when nodes are expected to belong to several groups at once; or when you need statistically tested community boundaries, since modularity optimization is a heuristic and does not itself provide significance tests.

Limitations and considerations

  • Resolution limit: optimizing Q tends to merge small modules into larger communities, so genuine small groups can be missed.
  • Because the optimum is approximated, stochastic optimizers may return different partitions on different runs, and a single partition may be one of several near-equal local maxima.
  • The null model preserves only node degrees. Communities are therefore judged against degree structure alone, and other constraints, such as geography or a known hierarchy, are not represented; some detected groups may reflect them rather than the relational pattern of interest.
  • Each node belongs to exactly one community, so the method cannot represent overlapping memberships.
  • The formula given is for undirected, unweighted graphs; directed and weighted networks need extended definitions with their own null models.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The number of communities is an output of the optimization rather than an input, which suits exploratory analysis when the number of groups is unknown.
  • Q gives one score for any partition of a given network, so alternative partitions of the same graph can be ranked on a common scale; scores are not directly comparable across different networks.
  • The spectral formulation (Newman, 2006) expresses Q through eigenvectors of the modularity matrix, giving a spectral route to candidate splits.
  • Approximate optimizers such as the Louvain method can be applied to networks far larger than those that exact search could handle.
  • Implemented in several widely used network analysis packages, which makes analyses easier to reproduce.

Applications

  • Detecting social factions, echo chambers, or collaboration clusters in online and offline social networks.
  • Identifying functional modules in biological networks such as protein-protein interaction and gene-regulatory graphs.
  • Revealing thematic or disciplinary clusters in citation and co-authorship networks.
  • Segmenting customer or product networks in marketing and recommendation systems.
  • Partitioning infrastructure networks (power grids, transportation) for resilience analysis.
  • Discovering topic communities in hyperlink or co-occurrence graphs in computational linguistics.

How it works

How it works

1

The network is stored as an adjacency matrix A, where A_ij is 1 if nodes i and j are linked and 0 otherwise, or as an equivalent edge list. The node degrees k_i and k_j and the total number of edges m are computed from this representation; these are the inputs the modularity formula needs.

2

Q is the share of edges that fall within communities minus the share expected under a configuration-model null, which randomly rewires edges while keeping each node's degree. In the formula above, k_i k_j / (2m) is the expected number of edges between nodes i and j under that null, and the delta term restricts the sum to node pairs in the same community. Q lies between roughly -0.5 and 1. A higher Q means more within-community edges than the null predicts, but no single value is a universal cut-off for meaningful structure.

Formula
Q = \frac{1}{2m}\sum_{ij}\left[A_{ij} - \frac{k_i k_j}{2m}\right]\delta(c_i, c_j)
3

Finding the partition with the globally highest Q is computationally hard, so practical methods search for good approximations. Common approaches include greedy local-move optimizers such as the Louvain method, the Leiden algorithm, a refinement of Louvain, spectral optimization using eigenvectors of the modularity matrix (Newman, 2006), and other stochastic search heuristics.

4

The optimizer moves nodes between communities and keeps moves that increase Q, so each node ends up in the community that gives the best overall partition under this search. Agglomerative methods such as Louvain typically return a hierarchy of partitions across levels, which allows inspection at coarser or finer scales. Spectral methods instead derive the split from eigenvectors of the modularity matrix and do not in general produce the same level-by-level hierarchy.

5

The partition is assessed by its Q value, by how stable it is across repeated runs with different random seeds, and, where a ground-truth partition exists, by external agreement measures such as normalized mutual information. To judge Q, generate a set of randomized copies of the network that preserve each node's degree, for example by degree-preserving edge swaps, optimize Q on each copy, and compare the observed Q with the resulting null distribution. Q that is low relative to these null values suggests weak community structure; interpret it together with the substantive content of the communities. This comparison is a descriptive check and not a formal significance test.

Common pitfalls

  • Accepting one run of a stochastic optimizer without checking stability across several random seeds.
  • Reading a large merged community as genuinely homogeneous when the resolution limit may have combined distinct modules; varying the resolution parameter, where available, can expose this.
  • Applying undirected modularity to a directed network, which discards edge direction, or using binary modularity on weighted edges without changing the null model.
  • Treating a high Q as validation of substantive meaning. Q measures edge concentration relative to the null model; it does not show that groups correspond to meaningful categories.
  • Comparing Q values across networks of different size or density as if they were on a common scale.

Frequently asked questions

What is a good value of Q?

There is no universal cut-off for Q. Interpret it relative to the network's size and density, and compare the observed Q with the values obtained for partitions of degree-preserving randomized versions of the same network. Large networks with weak structure can have modest Q and still reveal interpretable clusters, so examining the communities substantively is more informative than Q alone.

Which algorithm should I use to maximize Q?

Leiden is a refinement of the Louvain method. Louvain is a common, fast choice for large graphs. Spectral optimization of the modularity matrix (Newman, 2006) gives reproducible splits for a given eigensolver and its settings, and Newman (2006) reports higher-quality results in shorter running times than the competing methods it compares against.

Can modularity analysis detect overlapping communities?

Standard modularity optimization assigns each node to exactly one community and cannot detect overlap. If you expect nodes to belong to multiple groups simultaneously, use overlapping-community methods such as the clique-percolation method or non-negative matrix factorization approaches instead.

How does the resolution limit affect my analysis?

Modularity optimization can merge communities below a size scale, so small genuine clusters may be missed. Vary the resolution parameter, where your implementation provides one, and compare partitions across several values.

Should I apply modularity analysis to a directed network?

Use a directed formulation with a null model that preserves both in- and out-degree sequences, rather than undirected Q, which discards the direction of relationships. Check that the directed option in your software is documented for the method you need.

Related methods

Sources

  1. Newman, M. E. J., & Girvan, M. (2004). Finding and evaluating community structure in networks. Physical Review E, 69(2), 026113.

    Open DOI reference
  2. Newman, M. E. J. (2006). Modularity and community structure in networks. Proceedings of the National Academy of Sciences, 103(23), 8577–8582.

    Open DOI reference