Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Calinski-Harabasz and Davies-Bouldin Indices

Cluster Validity and Stability · Tutorial 265 of 700

Calinski-Harabasz and Davies-Bouldin Indices

Learn how to compute both indices, understand what they reward, and recognize when their geometric assumptions make them misleading for single-cell clusters.

Advanced 12 min read

What You'll Learn

  • Calculate the Calinski-Harabasz index from within-cluster and between-cluster sums of squares.
  • Calculate the Davies-Bouldin index from cluster scatter and centroid distances.
  • Explain why higher Calinski-Harabasz values and lower Davies-Bouldin values indicate preferred geometry.
  • Identify how unequal cluster sizes, singletons, and non-spherical structure can affect the indices.
  • Compare index values cautiously across candidate partitions and feature representations.
  • Distinguish internal validation scores from inferential tests and biological evidence.

Two Centroid-Based Views of Cluster Separation

The Calinski-Harabasz (CH) and Davies-Bouldin (DB) indices summarize different aspects of a partition in a feature space. CH compares between-cluster dispersion with within-cluster dispersion. DB asks whether each cluster is compact relative to its most similar neighboring cluster. Both are internal validity measures: they assess a partition using the data representation and cluster assignments, not external reference labels.

For single-cell data, the numerical values depend on the representation being evaluated: for example, a selected set of transformed expression features or a low-dimensional embedding. The indices do not establish that clusters correspond to distinct cell types. They describe geometric separation under the chosen representation and distance.

Definition: Let \(n\) observations \(x_1,\ldots,x_n\) be partitioned into \(k\) nonempty clusters \(C_1,\ldots,C_k\). Write \(n_j=|C_j|\), let \(\mu_j\) be the mean vector of cluster \(C_j\), and let \(\mu\) be the mean vector of all observations. In Euclidean feature space, define the within-cluster sum of squares \(W=\sum_{j=1}^k\sum_{x_i\in C_j}\|x_i-\mu_j\|^2\) and the between-cluster sum of squares \(B=\sum_{j=1}^k n_j\|\mu_j-\mu\|^2\). The Calinski-Harabasz index is \(CH=[B/(k-1)]/[W/(n-k)]\), defined for \(2\leq k<n\) and \(W>0\). Larger values indicate greater between-cluster dispersion relative to within-cluster dispersion.
Definition: For each cluster, define its scatter \(S_j=(1/n_j)\sum_{x_i\in C_j}\|x_i-\mu_j\|\), the mean Euclidean distance of its observations from its centroid. Let \(M_{j\ell}=\|\mu_j-\mu_\ell\|\). For each \(j\), define \(D_j=\max_{\ell\ne j}(S_j+S_\ell)/M_{j\ell}\). The Davies-Bouldin index is \(DB=(1/k)\sum_{j=1}^kD_j\), provided distinct cluster centroids have positive distance. Smaller values indicate that clusters are compact relative to their nearest competing cluster.

The indices use different summaries of spread. CH uses squared Euclidean distances in its sums of squares, whereas DB uses mean Euclidean distances from centroids. A CH value is not directly comparable with a DB value, and neither has a universal cutoff for “good” clustering.

Why the Calinski-Harabasz Ratio Has This Form

The CH index is a ratio of two mean-square quantities. The denominator \(W/(n-k)\) describes within-cluster squared dispersion per residual degree of freedom; the numerator \(B/(k-1)\) describes between-cluster squared dispersion per cluster degree of freedom. The degrees of freedom motivate the ratio, but do not make it an ordinary inferential F-test. In particular, cluster assignments are typically estimated from the same data being scored.

The decomposition \(T=W+B\), where \(T=\sum_i\|x_i-\mu\|^2\) is total squared dispersion, follows from centering each observation at its cluster centroid and then at the global centroid. For \(x_i\in C_j\), write \(x_i-\mu=(x_i-\mu_j)+(\mu_j-\mu)\). Summing squared norms gives a cross-product term proportional to \(\sum_{x_i\in C_j}(x_i-\mu_j)\), which is zero because \(\mu_j\) is the cluster mean. Thus the within- and between-cluster sums account for total dispersion exactly.

$$ \sum_{i=1}^n\|x_i-\mu\|^2 = \sum_{j=1}^k\sum_{x_i\in C_j}\|x_i-\mu_j\|^2 + \sum_{j=1}^k n_j\|\mu_j-\mu\|^2 =W+B. $$

A partition with small \(W\) and large \(B\) therefore tends to have a large CH value. However, \(B\) and \(W\) can change as the number of clusters changes. The degrees-of-freedom adjustment does not guarantee that the largest CH value identifies a biologically meaningful number of cell populations.

Worked Example: Calculating Both Indices for Two Clusters

Consider four hypothetical cells represented by one numeric feature, with values \(0,2,8,10\). Assign \(C_1=\{0,2\}\) and \(C_2=\{8,10\}\). The cluster centroids are \(\mu_1=1\) and \(\mu_2=9\); the global mean is \(\mu=5\). Each cluster has two cells, so \(n=4\) and \(k=2\).

For CH, the within-cluster sum of squares is

$$ W=[(0-1)^2+(2-1)^2]+[(8-9)^2+(10-9)^2]=2+2=4. $$

The between-cluster sum of squares is

$$ B=2(1-5)^2+2(9-5)^2=32+32=64. $$

Substitution gives

$$ CH=\frac{64/(2-1)}{4/(4-2)} =\frac{64}{2}=32. $$

For DB, each cluster’s mean distance to its centroid is \(1\), and the centroid distance is \(M_{12}=|9-1|=8\). There is only one competing cluster for each cluster, so

$$ D_1=D_2=\frac{1+1}{8}=0.25, \qquad DB=\frac{0.25+0.25}{2}=0.25. $$

These values describe this particular partition in this one-feature representation. CH \(=32\) is not a probability or a test statistic with a p-value; DB \(=0.25\) is not an error rate.

Unequal Cluster Sizes and the Nearest-Competitor Rule

The two indices weight clusters differently. In CH, every observation contributes to \(W\) and \(B\), so a large cluster has more influence on those sums than a small cluster. In DB, the final average gives each cluster’s \(D_j\) equal weight, regardless of its size. But \(D_j\) is determined by the largest scatter-to-separation ratio against any one competing cluster. A problematic close pair can therefore dominate the DB score even if other clusters are well separated.

Worked Example: An Unequal-Size Partition

Take the hypothetical one-dimensional clusters \(C_1=\{0,1,2,3\}\) and \(C_2=\{7,8\}\). Their centroids are \(1.5\) and \(7.5\), the global mean is \(3.5\), and \(n=6,\ k=2\).

For CH, the within-cluster sum of squares is \(W=5+0.5=5.5\): the first cluster contributes \(2.25+0.25+0.25+2.25=5\), and the second contributes \(0.25+0.25=0.5\). The between-cluster sum is

$$ B=4(1.5-3.5)^2+2(7.5-3.5)^2=16+32=48. $$

Therefore,

$$ CH=\frac{48/(2-1)}{5.5/(6-2)} =\frac{48}{1.375} \approx 34.91. $$

For DB, the mean distances to the centroids are \(S_1=(1.5+0.5+0.5+1.5)/4=1\) and \(S_2=(0.5+0.5)/2=0.5\). The centroid distance is \(6\), so

$$ DB=\frac{1}{2}\left(\frac{1+0.5}{6}+\frac{1+0.5}{6}\right)=0.25. $$

The relatively large first cluster contributes more observations to CH’s sums, while DB averages the two cluster-level ratios equally. Neither weighting scheme is automatically preferable; the relevant question is whether it matches the structure one wants to assess.

When the Indices Disagree

Because CH and DB summarize different quantities, they need not rank candidate partitions in the same order. DB can be especially vulnerable to singleton clusters: a singleton has zero distance from its own centroid, so it contributes zero scatter. This can make a partition’s DB value look favorable even when the extra cluster is not substantively useful.

Worked Example: A Singleton Can Lower DB

Use the same hypothetical values \(0,2,8,10\), but now consider three clusters: \(C_1=\{0,2\}\), \(C_2=\{8\}\), and \(C_3=\{10\}\). Their centroids are \(1,8,10\), and the global mean remains \(5\). Here \(n=4,\ k=3\).

The within-cluster sum of squares is \(W=2+0+0=2\). The between-cluster sum is

$$ B=2(1-5)^2+(8-5)^2+(10-5)^2=32+9+25=66. $$

Thus

$$ CH=\frac{66/(3-1)}{2/(4-3)}=\frac{33}{2}=16.5. $$

For DB, the scatters are \(S_1=1,\ S_2=0,\ S_3=0\). The three pairwise centroid distances are \(7,9,\) and \(2\). Hence \(D_1=1/7\), \(D_2=1/7\), and \(D_3=1/9\), giving

$$ DB=\frac{1}{3}\left(\frac{1}{7}+\frac{1}{7}+\frac{1}{9}\right) =\frac{25}{189}\approx 0.1323. $$

Relative to the two-cluster partition, CH falls from \(32\) to \(16.5\), while DB falls from \(0.25\) to about \(0.1323\). DB alone would favor the three-cluster partition, partly because the two singleton clusters have zero within-cluster scatter. This example shows why scores should be examined alongside cluster sizes and the actual partition, rather than optimized mechanically.

Assumptions, Diagnostics, and Limitations

These indices require a chosen representation, a distance, and a partition. The standard formulas above use Euclidean distances and arithmetic centroids. Their geometric summaries are most informative when centroids are meaningful and clusters are reasonably compact around them. They can be misleading for elongated, curved, nested, or otherwise non-convex groups: a centroid may lie in a low-density region or fail to represent the cluster’s structure. Two clusters may have similar centroid distances and scatter summaries while differing substantially in their shapes or connectivity.

For single-cell analysis, the following checks help interpret the scores:

  • Check the representation and scaling. A feature with a large numeric scale can dominate Euclidean distances. Recompute only after choosing a representation appropriate to the analysis question; changing feature scaling or embedding can change both indices.
  • Inspect cluster sizes and singleton counts. Very small clusters can distort interpretation, especially for DB, where singleton scatter is zero. A small cluster is not automatically invalid, but its score contribution deserves inspection.
  • Check centroids and distances. Identical centroids make DB undefined for that pair. Very small centroid distances can make a ratio large and unstable. Centroid distances also do not reveal every kind of overlap or non-convex structure.
  • Compare like with like. Scores are most interpretable when candidate partitions use the same cells, feature representation, distance, and preprocessing. Even then, changing \(k\) changes the index formulas and may change the balance of compactness and separation.
  • Look beyond one summary. The earlier material on silhouette widths assesses cell-level relative separation differently. It can provide a complementary view, but it too depends on the selected distance and representation.

Neither index accounts for biological interpretation, uncertainty in cell assignments, or whether an apparent group is reproducible under changes to the data or analysis. A high CH or low DB score is evidence only that a partition has favorable geometry according to that index. These are descriptive diagnostics, not p-values, confidence intervals, or proof that clusters are biologically distinct.

Common Mistakes

  • Choosing a partition solely because its score is extreme. More clusters can reduce within-cluster dispersion, while DB can reward singleton clusters. Inspect sizes, assignments, and the representation as well.
  • Interpreting DB as a probability or percentage. It is an average of ratios of distances, not an error probability. Lower values indicate more favorable compactness relative to centroid separation under the definition used.
  • Treating CH as an inferential F-test. Its ratio resembles a mean-square ratio, but ordinary F-test conclusions do not follow from calculating it on data-dependent clusters.
  • Assuming centroid summaries capture every cluster shape. They can miss curved or elongated structure. A favorable index does not establish that the clusters are separated in every meaningful sense.
Key takeaway: CH rewards a large between-to-within squared-dispersion ratio; DB rewards low average worst-competitor scatter relative to centroid distance. Use both as geometry-dependent summaries, check their assumptions and cluster sizes, and interpret them alongside other evidence.

Check Your Understanding

Try each question before reading the solutions below.

  1. For \(n=10\), \(k=2\), \(B=90\), and \(W=20\), calculate CH.
  2. Two clusters have scatters \(0.6\) and \(0.4\), and their centroid distance is \(5\). If these are the only two clusters, calculate DB.
  3. Why can adding singleton clusters make DB appear better even if the partition is not more useful?
  4. Does a high CH value show that a cluster partition is biologically correct? Explain.

Solutions. (1) \(CH=[90/(2-1)]/[20/(10-2)]=90/2.5=36\). (2) Each cluster has \(D=(0.6+0.4)/5=0.2\), so \(DB=(0.2+0.2)/2=0.2\). (3) A singleton has zero mean distance from its centroid, reducing its scatter contribution; DB may therefore decrease even though the added group is not substantively meaningful. (4) No. CH summarizes between- and within-cluster squared dispersion in the selected representation. It does not establish biological identity, reproducibility, or correctness.

Clinical Biostats