Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Distance Geometry Can Distort Validity Scores

Cluster Validity and Stability · Tutorial 284 of 700

Distance Geometry Can Distort Validity Scores

Learn how dimensionality, sparsity, and the choice of dissimilarity can change internal validity scores, and how to diagnose metric dependence without treating one score as definitive.

Advanced 11 min read

What You'll Learn

  • Define a metric and distinguish it from a general dissimilarity.
  • Explain why distances can concentrate as the number of dimensions grows.
  • Calculate silhouette scores and see how they depend on the distance choice.
  • Match Euclidean, Manhattan, cosine, and Jaccard dissimilarities to data geometry.
  • Diagnose when scaling, sparsity, or high dimensionality makes an internal score misleading.

Why a Validity Score Depends on Geometry

An internal cluster-validity index evaluates a partition using the data representation and a chosen measure of separation. It does not compare clusters with an external truth. Consequently, a high score is evidence that the partition fits a particular geometry—not proof that it captures biologically distinct cell types. In single-cell analyses, the same partition can look compact under one dissimilarity and diffuse under another, especially when the representation is high-dimensional or sparse.

This tutorial focuses on how geometry can affect internal scores, using the silhouette as a concrete example. The central diagnostic is to ask whether the score's conclusion persists under other defensible distance choices. Such comparisons are informative only when each choice has a clear interpretation for the representation being analyzed.

Definition: A metric \(d\) on a space of observations is a function that is nonnegative, has zero self-distance, satisfies identity of indiscernibles (\(d(x_i,x_j)=0\) only when \(x_i=x_j\)), is symmetric, and satisfies the triangle inequality. A dissimilarity is a measure of pairwise difference that need not satisfy every metric condition. Many internal indices can be computed with dissimilarities, but their geometric interpretation depends on the particular choice.

For vectors \(x_i\) and \(x_j\), Euclidean distance measures straight-line separation, while Manhattan distance sums absolute coordinate differences. Cosine dissimilarity measures angular difference and ignores vector magnitude; it is commonly useful as a dissimilarity, though \(1-\)cosine similarity is not generally a metric. Jaccard dissimilarity is often used for binary features, such as presence or absence, and is not a generic choice for continuous expression values.

$$ d_E(x_i,x_j)=\sqrt{\sum_{g=1}^{p}(x_{ig}-x_{jg})^2}, \qquad d_M(x_i,x_j)=\sum_{g=1}^{p}|x_{ig}-x_{jg}|, \qquad d_{\mathrm{cos}}(x_i,x_j)=1-\frac{x_i^\mathsf{T}x_j}{\|x_i\|\|x_j\|} $$

Here, \(p\) is the number of coordinates in the representation, such as genes or retained components. Cosine dissimilarity is undefined if either vector has zero norm; zero vectors must be handled explicitly rather than assigned an arbitrary cosine value. Euclidean and Manhattan distances are metrics on ordinary real vectors. A metric also depends on the coordinate scale: rescaling a feature changes its contribution to these distances.

Silhouette Scores and Their Assumptions

For a fixed partition into at least two clusters, let \(a_i\) be the mean distance from observation \(i\) to the other observations in its own cluster. For any other cluster, compute the mean distance from \(i\) to the observations in that cluster; let \(b_i\) be the smallest of those means. The silhouette for \(i\) compares its within-cluster distance with its nearest alternative cluster.

Definition: For an observation assigned to a cluster containing at least two observations, its silhouette is defined by the formula below; if \(a_i=b_i=0\), set \(s_i=0\).
$$ s_i=\frac{b_i-a_i}{\max(a_i,b_i)}. $$

The score lies between \(-1\) and \(1\). Values near \(1\) indicate that the observation is, on average, closer to its own cluster than to the nearest alternative; values near \(0\) indicate similar average distances; negative values indicate that another cluster is closer on average. The overall silhouette is commonly the arithmetic mean of the individual \(s_i\). A singleton has no within-cluster comparison, so a common convention assigns it a silhouette of zero; the convention should be stated when singleton clusters occur.

The calculation assumes that the supplied pairwise distances are meaningful for the observations and that the partition is fixed while the score is computed. It does not assume that clusters are spherical or equally sized, but the score still rewards certain distance geometries and can respond to cluster size, density, and shape. It is not a test of a null hypothesis and does not provide a probability that a partition is correct.

Worked Example: Computing a Silhouette by Hand

Consider four hypothetical points on a line: cluster A contains 0 and 2, and cluster B contains 5 and 7. Use absolute distance, which in one dimension is both Euclidean and Manhattan distance. For the point at 0, its within-cluster mean distance is \(a_i=|0-2|=2\). Its mean distance to B is \((|0-5|+|0-7|)/2=(5+7)/2=6\), so \(b_i=6\).

Its silhouette is \(s_i=(6-2)/\max(2,6)=4/6=0.667\). For the point at 2, \(a_i=2\), and the mean distance to B is \((3+5)/2=4\), giving \(s_i=(4-2)/4=0.500\). By symmetry, the scores for 5 and 7 are 0.500 and 0.667. Thus the mean silhouette is \((0.667+0.500+0.500+0.667)/4=0.5835\), or about 0.583 using unrounded values. This score describes separation under this distance and partition; it does not establish that two real populations exist.

Why High Dimensionality Can Flatten Distance Contrast

In high dimensions, pairwise distances can become more alike. A simple derivation shows the mechanism under a specific model. Suppose observations have \(p\) independent coordinates, each distributed as \(N(0,\sigma^2)\). For two independently drawn observations \(X_i\) and \(X_j\), each coordinate difference is distributed as \(N(0,2\sigma^2)\). Therefore, the squared Euclidean distance divided by \(2\sigma^2\) has a chi-squared distribution with \(p\) degrees of freedom.

$$ \frac{\|X_i-X_j\|^2}{2\sigma^2}\sim\chi^2_p, \qquad E[\|X_i-X_j\|^2]=2p\sigma^2, \qquad \operatorname{CV}(\|X_i-X_j\|^2)=\sqrt{\frac{2}{p}}. $$

The coefficient of variation (standard deviation divided by mean) of the squared distance shrinks as \(p\) grows. For the distance itself, a large-\(p\) approximation gives a relative standard deviation of about \(1/\sqrt{2p}\). The derivation assumes independent Gaussian coordinates with equal variance; it is an illustration, not a universal model for expression data. Correlation, unequal feature scales, a low-dimensional signal, or a different distribution can change the behavior. Still, it explains why small relative differences in distances may become less informative as many dimensions contribute noise.

Worked Example: How Distance Concentration Scales

Suppose, hypothetically, that two independent points have 100 independent Gaussian coordinates, each with variance \(\sigma^2=1\). The expected squared Euclidean distance is \(2p\sigma^2=2(100)(1)=200\). Its coefficient of variation is \(\sqrt{2/100}=0.1414\). The approximate relative standard deviation of the Euclidean distance itself is \(1/\sqrt{2(100)}=0.07071\).

Under the same assumptions with \(p=1{,}000\), the expected squared distance is \(2{,}000\), its coefficient of variation is \(\sqrt{2/1{,}000}=0.04472\), and the approximate relative standard deviation of distance is \(1/\sqrt{2{,}000}=0.02236\). The typical distance increases, but its relative spread decreases. This does not mean all high-dimensional data have useless distances; it means that separation based on modest relative distance contrasts deserves scrutiny, particularly if many coordinates contribute little cluster signal.

Sparsity, Scaling, and the Choice of Dissimilarity

Single-cell expression data can be sparse: many recorded gene values are zero. In a sparse representation, Euclidean distances may be driven by which coordinates are nonzero, by a few large values, or by the overall scale of a cell's vector. A large shared set of zeros can also make two profiles appear similar under some measures even when their nonzero patterns differ. The exact effect depends on whether the representation contains raw counts, normalized values, transformed values, selected genes, or a lower-dimensional embedding.

No distance is automatically correct. Euclidean distance is interpretable when coordinate magnitudes and scaling are meaningful. Manhattan distance can reduce the influence of a single large coordinate relative to squaring deviations, but it still depends on feature scales. Cosine dissimilarity is appropriate when direction or relative profile is the target and overall magnitude is not; it discards magnitude by construction. Jaccard dissimilarity can compare sets of present features, but binarizing expression discards abundance information and requires a defensible definition of presence.

Changing the distance is not a neutral robustness check if it changes the scientific question. For example, a cosine-based score asks whether profiles point in similar directions; a Euclidean score also reflects their lengths. The metric should be selected based on the representation and target notion of similarity, not because it produces the largest validity score.

Worked Example: One Partition, Two Geometries

Consider hypothetical two-dimensional vectors with cluster A containing \(x_1=(1,0)\) and \(x_2=(10,0)\), and cluster B containing \(x_3=(0,1)\) and \(x_4=(0,10)\). Under Euclidean distance, each within-cluster distance is 9. For \(x_1\), distances to B are \(\sqrt{2}=1.414\) and \(\sqrt{101}=10.05\), so \(b_1=(1.414+10.05)/2=5.732\), while \(a_1=9\). Its silhouette is \((5.732-9)/9=-0.3631\).

For \(x_2\), the distances to B are \(\sqrt{101}=10.05\) and \(\sqrt{200}=14.14\), so \(b_2=(10.05+14.14)/2=12.10\), and \(a_2=9\). Thus \(s_2=(12.10-9)/12.10=0.2560\), using unrounded distances. The other two scores are symmetric: \(s_3=-0.3631\) and \(s_4=0.2560\). The mean Euclidean silhouette, computed from the unrounded scores, is about \(-0.05358\).

Under cosine dissimilarity, each within-cluster pair has identical direction, so its dissimilarity is \(1-1=0\). Each cross-cluster pair is orthogonal, so its dissimilarity is \(1-0=1\). Every point therefore has \(a_i=0\), \(b_i=1\), and \(s_i=(1-0)/1=1\); the mean is 1. The dramatic difference is not an arithmetic contradiction. Euclidean distance treats the tenfold magnitude difference within each cluster as substantial, while cosine dissimilarity ignores it. Which conclusion is useful depends on whether magnitude is meaningful for the intended comparison.

A Practical Diagnostic for Metric Dependence

A diagnostic should make the comparison interpretable rather than search across distances until one score looks favorable. For a fixed partition, compute the same index using a small set of scientifically defensible distances on the same stated representation. Record the preprocessing, distance, index, and any special conventions. If the partition's apparent separation changes sharply, report that dependence and investigate which geometric feature drives it.

1
Specify the representation.
State what each vector contains, which features or components are included, and whether features have been scaled. Distances on different representations are not directly interchangeable.
2
Choose meaningful alternatives.
For example, compare magnitude-sensitive Euclidean distance with cosine dissimilarity only if both magnitude and direction are plausible notions of similarity for the question.
3
Recompute and inspect.
Compare individual and average silhouettes, cluster sizes, and the pairwise-distance distributions. Check whether a result is driven by a few extreme distances, many ties, zero vectors, or nearly identical pairwise distances.
4
Interpret conditionally.
Describe the score as support for separation under the stated representation and dissimilarity. If conclusions differ, state what each choice emphasizes instead of declaring one universally correct.

Useful diagnostics include plotting or summarizing the distribution of pairwise distances, checking how many distances are zero or tied, and examining whether a few features dominate Euclidean or Manhattan distances. In high dimensions, inspect relative contrasts, not only the absolute scale of distances. In sparse data, check whether zeros represent meaningful absence or arise from measurement and preprocessing. Cosine calculations require nonzero vectors, while Jaccard requires an explicit binary definition.

Other internal indices can have different geometric sensitivities. The Davies–Bouldin index compares within-cluster scatter with distances between cluster centers, and the Calinski–Harabasz index is based on between- and within-cluster sums of squares; these are not interchangeable with silhouette scores and commonly rely on Euclidean centroid geometry. Agreement across such indices can be reassuring, but disagreement can reflect different definitions of compactness and separation, not necessarily a computational error. Choosing among them requires understanding their assumptions rather than treating an index as a universal ranking.

Common Pitfalls and Limits

  • Calling every dissimilarity a metric. A distance-like formula may fail identity of indiscernibles or the triangle inequality. State whether it is a metric or a general dissimilarity; do not infer metric properties merely from its name.
  • Reading a high silhouette as biological truth. The score describes geometric separation for a chosen representation and partition. It does not establish a cell type, causal mechanism, or external validity.
  • Changing several choices at once. If representation, scaling, clustering, and distance all change, the source of a score change is unclear. For a distance-dependence check, hold the partition and representation fixed where possible.
  • Maximizing the score over many distances. Selecting the most favorable result after trying many choices creates a selectively optimistic summary. Define plausible choices in advance and report the comparison.
  • Ignoring degenerate cases. Singleton clusters, zero vectors for cosine calculations, and heavy ties in sparse data require explicit handling. A software default can affect the reported score.

Distance comparisons are diagnostics, not a method for proving which geometry is biologically correct. Internal scores are limited summaries: they compress pairwise structure, can be sensitive to cluster shape and size, and do not by themselves distinguish discrete populations from other patterns. Their strongest use is conditional description alongside a clear account of representation and distance.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. For \(p=200\) independent Gaussian coordinates with common variance, what is the coefficient of variation of squared Euclidean distance under the model above?
  2. A cell vector is zero in every coordinate. What is its cosine dissimilarity to another vector?
  3. For an observation with \(a_i=3\) and \(b_i=2\), calculate its silhouette and interpret its sign.
  4. Why can a cosine silhouette be high while a Euclidean silhouette is low for the same partition?

Solutions. (1) \(\sqrt{2/200}=\sqrt{0.01}=0.1000\). (2) It is undefined because the cosine formula divides by the vector norm, which is zero; a handling rule must be specified. (3) \(s_i=(2-3)/\max(3,2)=-1/3=-0.3333\). The observation is, on average, closer to another cluster than to its assigned cluster under that dissimilarity. (4) Cosine dissimilarity ignores vector magnitude and compares directions, whereas Euclidean distance is sensitive to both direction and magnitude. If within-cluster magnitude differences are large but directions are similar, the two scores can differ substantially.

Clinical Biostats