Tutorials › Statistical Methods for Single-Cell RNA Sequencing › The Resolution Parameter in Modularity Clustering

Graph-Based Clustering · Tutorial 251 of 700

The Resolution Parameter in Modularity Clustering

See how changing the modularity resolution parameter changes partition scores and the community scales that modularity tends to favor.

Intermediate 11 min read

What You'll Learn

  • Define the resolution-parameter version of modularity for an undirected weighted graph.
  • Calculate a partition’s modularity score at different parameter values.
  • Derive the condition under which merging two communities raises the score.
  • Interpret why larger parameter values tend to favor finer partitions without guaranteeing them.
  • Identify common errors in comparing scores and interpreting the parameter.

Why Modularity Has a Resolution Parameter

A community is a group of vertices with more internal connectivity than a specified reference model would predict. Modularity quantifies that contrast. Its resolution parameter, usually written \(\gamma\), controls how strongly the reference model’s expected internal connectivity is counted against a partition. Changing \(\gamma\) can therefore change which community sizes score well, even when the graph itself is unchanged.

In a cell-neighborhood graph, vertices represent cells and edges represent neighborhood relationships or their weights. The resolution parameter does not alter those edges; it changes the objective used to score a proposed partition. It is a tuning parameter, not a probability, a significance level, or a measure of biological effect.

Definition and Assumptions

We use an undirected graph with nonnegative edge weights and no self-loops. Let \(A_{ij}=A_{ji}\) be the weight between vertices \(i\) and \(j\), with \(A_{ij}=0\) when there is no edge. For an unweighted graph, an existing edge has weight 1. Define the degree or strength of vertex \(i\) as \(k_i=\sum_j A_{ij}\), and let \(m=\frac{1}{2}\sum_{i,j}A_{ij}\) be the total edge weight. Thus each undirected edge contributes its weight once to \(m\), although it appears twice in the sum over ordered vertex pairs.

Definition: For a partition with community label \(c_i\) for vertex \(i\), the resolution-parameter modularity is
$$ Q_\gamma=\frac{1}{2m}\sum_{i,j}\left(A_{ij}-\gamma\frac{k_i k_j}{2m}\right)\mathbf{1}(c_i=c_j), $$
where \(\mathbf{1}(c_i=c_j)\) equals 1 when \(i\) and \(j\) belong to the same community and 0 otherwise. The usual modularity objective is recovered at \(\gamma=1\). The parameter \(\gamma\) is ordinarily positive.

The term \(k_i k_j/(2m)\) is the expected edge weight between vertices \(i\) and \(j\) in the configuration-model reference used by modularity: the reference preserves the graph’s degree or strength totals in expectation. Modularity compares observed edge weight with this degree-based expectation. The choice of reference model is part of the objective, not a claim that the graph was literally generated by that model.

For calculations, it is often easier to sum by community. Let \(L_C\) be the total weight of edges whose two ends lie in community \(C\), counted once per undirected edge, and let \(K_C=\sum_{i\in C}k_i\) be that community’s total degree or strength. Then the same score is

$$ Q_\gamma=\sum_C\left[\frac{L_C}{m}-\gamma\left(\frac{K_C}{2m}\right)^2\right]. $$

The \(L_C/m\) term rewards observed internal weight. The second term penalizes the amount expected internally under the degree-based reference model, with the penalty scaled by \(\gamma\). Both formulas assume an undirected graph; directed modularity uses a different null-model expression and should not be obtained by silently reusing this one.

Worked Example: Recalculating a Fixed Partition

Consider a hypothetical weighted graph with total edge weight \(m=8\), partitioned into communities \(C_1\) and \(C_2\). Suppose their internal edge weights are \(L_1=4\) and \(L_2=3\), and their total strengths are \(K_1=9\) and \(K_2=7\). These totals are consistent: \(K_1+K_2=16=2m\). Calculate the score at \(\gamma=1\) and \(\gamma=1.5\).

Using the community-sum formula,

$$ Q_\gamma=\frac{4}{8}+\frac{3}{8} -\gamma\left[\left(\frac{9}{16}\right)^2+\left(\frac{7}{16}\right)^2\right] =0.875-\gamma\left(\frac{130}{256}\right). $$

Since \(130/256=0.5078125\), at \(\gamma=1\) the score is \(0.875-0.5078125=0.3671875\), or approximately 0.3672. At \(\gamma=1.5\), it is \(0.875-1.5(0.5078125)=0.11328125\), or approximately 0.1133. The same partition has a lower score at the larger parameter value. This calculation alone does not show that another partition scores better; that requires comparing candidate partitions at the same \(\gamma\).

How the Parameter Changes Scores

For any fixed partition, the score is a linear function of \(\gamma\). In the community-sum form, its slope is

$$ \frac{dQ_\gamma}{d\gamma} =-\sum_C\left(\frac{K_C}{2m}\right)^2. $$

For a nonempty graph with positive-strength communities, this slope is negative. Thus raising \(\gamma\) lowers the score of each such fixed partition. The useful question is not whether a particular score rises or falls, but how the scores of competing partitions change relative to one another. A partition with many small communities and a partition with a few large communities generally have different penalty terms.

The merge comparison makes that difference explicit. Consider two communities \(A\) and \(B\), with total strengths \(K_A\) and \(K_B\), and let \(w_{AB}\) be the total edge weight between them. Compare a partition in which they are separate with the otherwise identical partition in which they are merged. The change in score from merging is

$$ Q_{\mathrm{merged}}-Q_{\mathrm{separate}} =\frac{w_{AB}}{m} -\gamma\frac{K_AK_B}{2m^2}. $$

The first term is the internal-edge reward newly gained by merging. The second is the extra null-model penalty. Merging raises the score exactly when \(w_{AB}>\gamma K_AK_B/(2m)\); separating raises it when the inequality is reversed. Equality means the two alternatives have equal scores. This is a comparison of these two partitions, not necessarily a proof that either is the globally best partition.

A Merge Threshold in a Weighted Graph

Worked Example: Finding the Parameter at Which a Merge Stops Helping

In a hypothetical graph, \(m=12\). Two candidate communities \(A\) and \(B\) have strengths \(K_A=8\) and \(K_B=10\), with edge weight \(w_{AB}=2\) between them. A third community \(R\) has strength 6. The graph summaries can be consistent with these values: take weights 1 between \(A\) and \(R\), 1 between \(B\) and \(R\), and internal weights 2.5, 3.5, and 2 in \(A\), \(B\), and \(R\), respectively. The internal and between-community weights sum to \(12\), and the strengths sum to \(24=2m\).

The score change from merging \(A\) and \(B\), leaving \(R\) unchanged, is

$$ Q_{\mathrm{merged}}-Q_{\mathrm{separate}} =\frac{2}{12}-\gamma\frac{8(10)}{2(12)^2} =\frac{1}{6}-\frac{5\gamma}{18}. $$

Setting this difference to zero gives \(\gamma=3/5=0.6000\). At \(\gamma=0.5\), the difference is \(1/6-5(0.5)/18=1/36\approx0.02778\), so merging these two groups improves the score by about 0.02778. At \(\gamma=1\), it is \(1/6-5/18=-1/9\approx-0.1111\), so keeping them separate scores higher than merging them. Other possible rearrangements of the graph’s vertices could still have higher scores.

Why Larger Values Tend to Favor Finer Partitions

In the merge comparison, increasing \(\gamma\) increases the penalty for joining communities while leaving their observed between-community weight unchanged. Consequently, a merge that is favorable at a low value may become unfavorable at a higher one. This is why larger \(\gamma\) values tend to favor finer, more numerous communities, while smaller values tend to make coarser groupings more competitive.

This tendency is not a guarantee that every increase in \(\gamma\) splits a community, or that the resulting partitions form a perfectly nested sequence. The optimization compares many possible partitions at once; the best-scoring partition can change in more complicated ways than a single pairwise merge. In addition, a community-detection algorithm may use a heuristic search rather than find the global maximum. The parameter changes the objective, while the algorithm searches that objective.

Worked Example: Comparing Coarse and Fine Candidate Partitions

Consider a hypothetical unweighted graph made of two triangles joined by one bridge edge. There are \(m=7\) edges. Each triangle has internal edge weight 3 and total degree 7: its two bridge-end vertices have degree 3, and its third vertex has degree 2. Compare the partition that keeps the triangles separate with the partition that puts all six vertices into one community.

For the separate-triangle partition, the score is

$$ Q_{\mathrm{separate}} =2\left[\frac{3}{7}-\gamma\left(\frac{7}{14}\right)^2\right] =\frac{6}{7}-\frac{\gamma}{2}. $$

For the one-community partition, all seven edges are internal and the total strength is \(14\), so

$$ Q_{\mathrm{one}} =\frac{7}{7}-\gamma\left(\frac{14}{14}\right)^2 =1-\gamma. $$

At \(\gamma=0.2\), the separate partition scores \(6/7-0.1\approx0.7571\), while the one-community partition scores \(0.8\). Of these two candidates, the coarser partition scores higher. At \(\gamma=1\), the separate partition scores \(6/7-0.5\approx0.3571\), while the one-community score is 0. Of these two candidates, the finer partition scores higher. This comparison illustrates the scale effect; it does not establish that either candidate beats every other possible partition.

Diagnostics, Comparisons, and Limitations

When examining a resolution parameter’s effect, keep the graph, its weights, and the scoring convention fixed. Compare the resulting partitions at each parameter value, and check whether the change is consistent with the score calculations for important merges or splits. If changing \(\gamma\) produces an unexpected result, verify that the software actually applies it to the intended modularity objective and that the graph has not also been transformed.

  • Scores are parameter-dependent. A fixed partition’s score decreases as \(\gamma\) rises, so raw modularity values from different parameter settings are not a direct measure of which setting is preferable.
  • The number of communities need not change smoothly. A small parameter change can switch the best-scoring partition, while a larger change may leave it unchanged. Non-nested changes are possible.
  • Optimization can affect the result. Louvain and Leiden are methods for searching for high-modularity partitions; neither changes the meaning of \(\gamma\). Heuristic search may return different partitions, so a score comparison should not be mistaken for a guarantee of a global optimum.
  • The graph and null model matter. The interpretation above relies on the stated undirected, nonnegative-weight setup and degree-based reference. A directed graph or a different objective requires its corresponding formulation.

The parameter is not an inferential test: it supplies no \(p\)-value, confidence interval, or probability that a community is real. Nor does a smaller-scale partition automatically have more biological validity. Modularity describes how well a partition scores under its objective; biological interpretation requires evidence beyond the score itself. A further limitation of the modularity objective concerns the scales it can represent on large graphs, which is a distinct issue from the arithmetic effect of \(\gamma\) on a fixed graph and partition.

Common Mistake

Common mistake: “The score for my partition fell when I raised \(\gamma\), so the clustering got worse.” For a fixed partition, the score is expected to fall because the null-model penalty is multiplied by a larger \(\gamma\). The relevant comparison is between candidate partitions evaluated at the same parameter value. A lower score across different parameter values does not, by itself, indicate a worse clustering.
Key takeaway: The resolution parameter scales modularity’s degree-based expected-edge penalty. For a fixed partition it lowers the score as it increases, but its effect on the preferred partition is determined by comparing alternatives at the same value of \(\gamma\). Larger values tend to favor finer groupings, without guaranteeing a simple or biologically meaningful sequence of splits.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. For a fixed partition, why does increasing \(\gamma\) lower \(Q_\gamma\)? Does that alone show that the partition is less preferred?
  2. Two communities have \(m=10\), \(K_A=6\), \(K_B=8\), and between-community edge weight \(w_{AB}=2\). At what value of \(\gamma\) are merging and keeping them separate tied?
  3. In the preceding question, does merging raise the score at \(\gamma=0.5\)? Show the score difference.
  4. State one reason why a higher \(\gamma\) should not be interpreted as a guarantee that every community will split.

Solutions. (1) The score has slope \(-\sum_C(K_C/(2m))^2\), which is negative for positive-strength communities. That fact concerns one fixed partition only; preference requires comparing its score with other partitions at the same \(\gamma\). (2) A tie occurs when \(w_{AB}/m=\gamma K_AK_B/(2m^2)\), so \(\gamma=2mw_{AB}/(K_AK_B)=2(10)(2)/(6\cdot8)=5/6\approx0.8333\). (3) The merge difference is \(2/10-0.5[6(8)/(2(10)^2)]=0.2-0.12=0.0800\), so merging raises the score by 0.0800. (4) The optimal partition is chosen from many possible groupings, and their scores can change relative to one another in non-nested ways; heuristic optimization can also affect the returned result.

Clinical Biostats