Why Distance Comes Before an Embedding
A low-dimensional plot is not a direct picture of all expression values. It is an embedding constructed from relationships among cells, and those relationships depend partly on how similarity is measured. Two cells can be close because their expression levels are similar in magnitude, because their profiles rise and fall in similar patterns, or because a chosen transformation makes them close. These are different claims about the data.
Before interpreting a PCA, t-SNE, or UMAP visualization, it is therefore useful to ask what geometry the method received. In this tutorial, a cell's expression profile is a vector across a common set of genes. The distance between two such vectors is calculated after choices about normalization, transformation, feature selection, and possibly gene scaling. Those choices define what “nearby cells” means for the analysis.
Euclidean distance is a metric: it is nonnegative, symmetric, zero only for identical vectors, and satisfies the triangle inequality. Correlation dissimilarity ranges from 0 to 2, but it is not generally a metric. It measures profile alignment after each profile is centered across genes, so it largely ignores overall level and positive rescaling. A zero correlation distance means perfect positive correlation, not necessarily identical expression vectors.
What the Two Distances Emphasize
Euclidean distance responds to differences in the actual coordinates. A large difference in a gene contributes its squared difference to the distance, so genes with large numerical scales can dominate. If one cell has twice the expression of another across every gene, their Euclidean distance will usually be positive even though their profiles have the same shape.
Correlation compares the pattern of deviations from each cell's own average expression across the selected genes. If one profile is a positive affine transformation of another, their correlation is 1 and their correlation dissimilarity is 0, even though their absolute levels differ. The direction of the pattern matters: profiles that vary in opposite directions can have negative correlation and a correlation dissimilarity near 2.
For correlation to be defined, each profile must vary across the genes used. If a cell has exactly the same value for every selected gene, its profile standard deviation is zero and its correlation with another profile is undefined. Correlations also depend on the set of genes included: changing the genes changes the pattern being compared.
Worked Example: Euclidean and Correlation Distances Can Disagree
Suppose a hypothetical, already transformed expression matrix has three cells and three genes:
| Cell | Gene 1 | Gene 2 | Gene 3 |
|---|---|---|---|
| A | 1 | 2 | 3 |
| B | 2 | 4 | 6 |
| C | 1 | 3 | 2 |
For Euclidean distance, subtract the vectors and take the square root of the sum of squared differences:
For the other pairs, \(d_E(A,C)=\sqrt{(1-1)^2+(2-3)^2+(3-2)^2}=\sqrt{2}\approx1.414\), and \(d_E(B,C)=\sqrt{(2-1)^2+(4-3)^2+(6-2)^2}=\sqrt{18}\approx4.243\). Thus A and C are the closest pair by Euclidean distance.
For correlation, center each profile by its own mean. The centered profiles are \(A=(-1,0,1)\), \(B=(-2,0,2)\), and \(C=(-1,1,0)\). Their correlations are \(r_{AB}=1\), \(r_{AC}=1/2\), and \(r_{BC}=1/2\). Consequently, \(d_C(A,B)=0\), while \(d_C(A,C)=d_C(B,C)=0.5\).
The two measures tell different stories. Euclidean distance places A closer to C than to B, because A and C have smaller absolute coordinate differences. Correlation treats A and B as identical in profile shape because B is twice A, and places C equally far from both. Neither calculation is erroneous; they answer different questions.
A Useful Connection Between Correlation and Euclidean Geometry
Correlation distance has a geometric interpretation that makes its behavior precise. First center each cell's profile across genes, then divide by its Euclidean length. Call the resulting unit-length vector \(u_i\). Its dot product with \(u_j\) is the Pearson correlation \(r_{ij}\). The squared Euclidean distance between these normalized vectors is therefore:
Both vectors have length 1, which gives the third equality. Thus correlation dissimilarity is half a squared Euclidean distance between centered, normalized profiles. This explains why correlation ignores profile magnitude: normalization puts each nonconstant centered profile at unit length before comparing directions.
The square matters. Squared Euclidean distance does not generally satisfy the triangle inequality, which is why \(1-r\) is not generally a metric. For example, take three unit vectors at angles \(0^\circ\), \(60^\circ\), and \(120^\circ\). The correlation dissimilarities for the first-to-second and second-to-third pairs are each \(0.5\), while the first-to-third dissimilarity is \(1.5\). Since \(1.5>0.5+0.5\), the triangle inequality fails. This does not prevent a method from using correlation dissimilarities, but it does matter if a procedure specifically requires a metric.
Scaling and the Representation Define the Geometry
A distance is only as meaningful as the coordinates used to calculate it. In single-cell analysis, the coordinates might be raw counts, normalized counts, log-transformed values, a selected set of genes, or another representation. Raw counts often reflect sequencing depth as well as expression. If library sizes differ, Euclidean distances on raw counts can chiefly reflect that difference rather than the biological pattern of interest. A transformation can reduce or change such effects, but it also changes the geometry.
Feature scaling is another decision. Multiplying a gene's values by a constant multiplies its contribution to Euclidean squared distance by the square of that constant. Standardizing genes can prevent high-variance genes from dominating numerically, but may give noisy or low-information genes more influence. Correlation also depends on representation and gene selection, even though its profile-wise centering and normalization make it invariant to adding a constant to, or multiplying by a positive constant, an entire cell profile.
Worked Example: A Gene's Scale Changes Euclidean Neighbors
Consider three hypothetical cell profiles on two transformed genes: \(P=(0,0)\), \(Q=(10,0)\), and \(R=(0,2)\). In the original coordinates, \(d_E(P,Q)=\sqrt{10^2+0^2}=10\), while \(d_E(P,R)=\sqrt{0^2+2^2}=2\). By this measure, P is much closer to R.
Now consider a deliberate rescaling in which Gene 1 is divided by 10 and Gene 2 by 2. The rescaled profiles are \(P'=(0,0)\), \(Q'=(1,0)\), and \(R'=(0,1)\). The distances become \(d_E(P',Q')=1\) and \(d_E(P',R')=1\). The earlier preference for R disappears.
The arithmetic shows that scaling is not a cosmetic step: it changes which differences count most. The divisors here are illustrative choices, not estimates from a study. In an analysis, scaling should be justified by the scientific meaning of the genes and the intended representation.
For distances to be comparable, cells must be represented using the same genes, in the same order, with compatible preprocessing. If some cells have missing coordinates and others do not, calculating distances from different subsets can make pairwise values incomparable. When distances are calculated on an integrated representation rather than gene-expression vectors, the resulting geometry answers a question about that representation; it is not automatically the geometry of the original expression matrix.
How the Geometry Relates to PCA, t-SNE, and UMAP
PCA is a linear representation of the data. With all nonzero principal components retained, its orthogonal change of coordinates preserves Euclidean distances in the centered input space. Retaining only a subset projects cells onto a lower-dimensional subspace; this can shorten distances and can make distinct cells appear identical in the retained coordinates. The distance geometry of PCA therefore depends on both the input representation and how many components are retained.
The usual PCA input is centered gene by gene across cells. Subtracting the same gene mean from every cell does not change any pairwise Euclidean distance, because for each gene the difference between two cells is unchanged. This fact does not mean all preprocessing choices are irrelevant: scaling genes or transforming expression values does change the differences.
t-SNE and UMAP use input-space distances to establish local relationships among cells before constructing a low-dimensional visualization. In broad terms, t-SNE converts distances into neighborhood similarities, while UMAP constructs a nearest-neighbor graph from the input representation. These methods do not promise that every distance in a two-dimensional plot equals its input-space counterpart. Their plots emphasize particular aspects of neighborhood structure, and visual gaps or cluster sizes should not be read as direct measurements of global expression distance.
The practical implication is that the distance choice is upstream of the visualization. If Euclidean distance is dominated by a scale difference, the resulting neighborhoods may reflect that difference. If correlation makes cells with different overall levels neighbors because their profiles are aligned, that is the intended consequence of the chosen dissimilarity, not a property discovered independently by the embedding.
Worked Example: Truncating a Linear Representation Can Lose Distance
To isolate the geometry of projection, consider three hypothetical points in a two-coordinate representation: \(A=(0,0)\), \(B=(3,0)\), and \(C=(0,4)\). Their full Euclidean distances are \(d_E(A,B)=3\), \(d_E(A,C)=4\), and \(d_E(B,C)=\sqrt{3^2+4^2}=5\).
Suppose a one-dimensional representation retains only the first coordinate. The projected points are \(A'=(0)\), \(B'=(3)\), and \(C'=(0)\). The projected distances are 3, 0, and 3, respectively. A and C, which were four units apart, have collapsed to the same projected coordinate.
This projection is an illustration of dimensional truncation, not a claim that this axis was calculated as a principal component for these points. In general, for an orthogonal projection \(P\), the difference vector splits into its projected and discarded components. By the Pythagorean theorem, \(\lVert x_i-x_j\rVert^2=\lVert P(x_i-x_j)\rVert^2+\lVert (I-P)(x_i-x_j)\rVert^2\), so the projected distance cannot exceed the full distance.
Diagnostics, Alternatives, and Common Pitfalls
Distance choices should be checked rather than treated as invisible defaults. Useful checks include confirming that every cell uses the same features and preprocessing; inspecting whether a small number of genes dominate Euclidean distance; checking for constant profiles before calculating correlations; and comparing nearest neighbors under scientifically plausible transformations or scaling choices. If small reasonable changes produce very different neighborhoods, the geometry is sensitive and downstream visual conclusions should be qualified.
Euclidean distance is a natural choice when the magnitude of coordinate differences is meaningful and the input has been made comparable across cells and genes. Correlation dissimilarity is useful when relative profile shape is more central than overall level. Neither is universally preferable. If a method requires a metric, correlation dissimilarity needs special care; one alternative is the chord distance \(\sqrt{2(1-r)}\), which is Euclidean distance between the centered, normalized profiles when those profiles are defined.
- Pitfall: “Correlation distance zero means the cells have the same expression.” That is false. In the worked matrix, B is twice A, yet their correlation distance is zero. The correction is that zero correlation distance means the profiles are perfectly positively correlated across the selected genes.
- Pitfall: “A visible gap in an embedding proves a large input-space distance.” The embedding is a lower-dimensional construction that may preserve local relationships while changing other distances. Interpret the plot in light of the method and input geometry; do not treat every plotted gap as an original expression distance.
- Pitfall: “Standardizing genes is always safer.” It changes the relative contribution of genes and can amplify low-variance noise. Choose scaling for a stated reason, then check whether relevant neighborhoods are robust to reasonable alternatives.
Ultimately, distance is a modeling decision about what differences between cells matter. Reporting the representation and distance used makes an embedding easier to interpret and reproduce. A persuasive visualization cannot compensate for a geometry that measures an unintended feature of the data.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- Two cell profiles are \(x=(1,2,3)\) and \(y=(2,4,6)\). What are their Euclidean distance and correlation dissimilarity, and what do the results imply?
- Why can multiplying one gene's values by 5 change Euclidean distances, while multiplying an entire nonconstant cell profile by a positive constant does not change its correlation with another profile?
- For an orthogonal projection, can a projected pairwise distance exceed the original distance? Explain using the decomposition of the difference vector.
- What does correlation dissimilarity equal to 0.5 mean, and what does it not establish?
Solutions. 1. The Euclidean distance is \(\sqrt{1^2+2^2+3^2}=\sqrt{14}\approx3.742\). The profiles are proportional, so their correlation is 1 and their correlation dissimilarity is 0; they have the same profile shape but not the same values. 2. Scaling one gene changes only that coordinate's contribution to Euclidean distance, while multiplying a whole profile by a positive constant leaves its centered direction unchanged and therefore leaves its correlation unchanged. 3. No. The squared original distance is the sum of the squared projected and discarded components, so the projected distance cannot be larger. 4. It means the Pearson correlation is \(1-0.5=0.5\) across the selected genes. It does not establish equal overall expression levels, identical profiles, or a particular global distance in a later embedding.