Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Compositional Constraints in Spatial Proportion Maps

Spatial Transcriptomics · Tutorial 653 of 700

Compositional Constraints in Spatial Proportion Maps

Learn why spatial cell-type proportions are compositional, how to compare them with log-ratio contrasts, and how to recognize correlations that arise from the sum-to-one constraint.

Advanced 12 min read

What You'll Learn

  • Explain why a vector of cell-type fractions has only one fewer independent component than its number of cell types.
  • Construct and interpret log-ratio contrasts between cell types across spatial locations.
  • Calculate a regional difference in mean log-ratio and express it as a relative fold change.
  • Identify how closure can induce negative correlations between fractions even when underlying counts move together.
  • Diagnose zeros, changing denominators, and spatial dependence as potential sources of misleading conclusions.
  • Compare raw-proportion summaries with log-ratio and count-scale approaches.

Why Spatial Proportion Maps Are Constrained

A deconvolution map assigns each spatial location a vector of estimated cell-type fractions. Those fractions describe parts of a whole: when the represented cell types exhaust the mixture, the fractions at each location must add to one. This constraint is scientifically useful, but it has an important statistical consequence: a change in one fraction necessarily changes at least one other fraction, even if the corresponding cell populations do not directly interact.

Let \(i\) index spatial locations and \(k=1,\ldots,K\) index cell types. Write \(\hat{p}_{ik}\) for the estimated fraction of cell type \(k\) at location \(i\). For a complete composition, each fraction is nonnegative and \(\sum_{k=1}^{K}\hat{p}_{ik}=1\). The vector of fractions therefore lies on a \(K-1\) dimensional simplex, not in unrestricted \(K\)-dimensional space. If a deconvolution omits a relevant cell type or other component, the fractions may not represent the complete mixture; the omitted component should be considered explicitly rather than silently ignored.

Definition: A composition is a vector of nonnegative components whose total is fixed, commonly to one. Closure is the operation of dividing each positive component by the vector's total so that the resulting components sum to one. Spatial cell-type fractions are compositional when they represent shares of a common total.

Closure makes the components dependent by construction. The constraint does not imply that every pair of fractions must be negatively correlated in every data set, nor does it prove biological competition. It does mean that correlations and changes in raw fractions need careful interpretation: they concern relative shares of a total, not necessarily absolute cell abundance.

Log-Ratio Contrasts for Spatial Comparisons

A direct way to compare two cell types is to examine their ratio. At location \(i\), the log-ratio contrast between types \(A\) and \(B\) is \(\log(\hat{p}_{iA}/\hat{p}_{iB})\). It is positive when type \(A\) has the larger share, zero when the shares are equal, and negative when type \(B\) has the larger share. Because the ratio cancels any common scaling factor, it describes relative composition rather than the overall amount of material at a location.

Definition: For a composition with strictly positive components, a log-ratio contrast is \(L_i=\sum_{k=1}^{K}c_k\log(\hat{p}_{ik})\), where the contrast weights satisfy \(\sum_{k=1}^{K}c_k=0\). For two types, choosing weights \(1\) for \(A\), \(-1\) for \(B\), and \(0\) otherwise gives \(L_i=\log(\hat{p}_{iA}/\hat{p}_{iB})\).

The zero-sum condition on the weights makes the contrast invariant to a common rescaling. If positive unclosed quantities \(x_{ik}\) are multiplied by the same constant \(a\), then \(\sum_k c_k\log(a x_{ik})=\sum_k c_k\log(x_{ik})+\log(a)\sum_k c_k=\sum_k c_k\log(x_{ik})\). Thus, the contrast compares relative quantities and does not depend on their shared scale.

Worked Example: Comparing Two Cell Types Across Regions

Suppose two hypothetical spatial regions each contain two sampled locations with estimated fractions for types \(A\) and \(B\). In the west, the compositions for these two types are \((0.60,0.20)\) and \((0.40,0.40)\). In the east, they are \((0.30,0.30)\) and \((0.20,0.50)\). The remaining fraction at each location belongs to other types.

For each location, calculate \(L_i=\log(\hat{p}_{iA}/\hat{p}_{iB})\). The west contrasts are \(\log(0.60/0.20)=\log(3)=1.0986\) and \(\log(0.40/0.40)=0\). Their mean is \((1.0986+0)/2=0.5493\).

The east contrasts are \(\log(0.30/0.30)=0\) and \(\log(0.20/0.50)=\log(0.4)=-0.9163\). Their mean is \((0-0.9163)/2=-0.4581\). The east-minus-west contrast is \(-0.4581-0.5493=-1.0074\).

Exponentiating this difference gives \(\exp(-1.0074)=0.3651\). In this hypothetical example, the geometric-mean ratio of type \(A\) to type \(B\) in the east is about 0.365 times that ratio in the west. This describes a relative shift; it does not establish that the absolute number of type \(A\) cells fell. The calculation is descriptive, not a test of a regional effect.

For a spatial analysis, the contrast can be calculated at each location and related to coordinates, region, or another spatial covariate. If a regression is used, its coefficient describes change in the expected log-ratio on the model's chosen scale. The spatial dependence of locations still matters for uncertainty: treating nearby spots as independent observations can make uncertainty estimates too small. The earlier material on spatial effect models and spatial test calibration provides relevant approaches to that dependence; transforming to log-ratios does not remove it.

Why Closure Can Create Negative Correlations

The simplest illustration uses two components. If \(P_{iB}=1-P_{iA}\) at every location, then their sample covariance is exactly the negative of the sample variance of \(P_A\). In particular, if \(P_A\) varies, the correlation between the two fractions is \(-1\). This is an arithmetic consequence of closure, not evidence that the cell types inhibit one another.

With three or more components, the pairwise correlations are not fixed at \(-1\), but the sum constraint still couples them. A component's fraction can fall because its own abundance fell, because another component increased, or because the total changed. Correlation between fractions alone cannot distinguish those explanations.

Worked Example: Negative Fraction Correlation Despite Increasing Counts

Consider three hypothetical locations containing only types \(A\) and \(B\), with counts \((10,20)\), \((20,30)\), and \((40,40)\). Both cell-type counts increase across locations. The totals are 30, 50, and 80.

The corresponding fractions are \(A=(10/30,20/50,40/80)=(0.3333,0.4000,0.5000)\) and \(B=(20/30,30/50,40/80)=(0.6667,0.6000,0.5000)\). At every location, \(p_A+p_B=1\), so \(p_B=1-p_A\).

For any nonconstant sample \(p_A\), the sample covariance satisfies \(s_{AB}=\sum_i(p_{iA}-\bar{p}_A)(p_{iB}-\bar{p}_B)/(n-1)\). Since \(p_{iB}-\bar{p}_B=-(p_{iA}-\bar{p}_A)\), this becomes \(s_{AB}=-\sum_i(p_{iA}-\bar{p}_A)^2/(n-1)=-s_A^2\). The standard deviation of \(p_B\) equals that of \(p_A\), so their correlation is \(-1\).

Thus, the fractions are perfectly negatively correlated even though both counts rise. The fraction correlation reports the fixed-total tradeoff, not a negative relationship between the underlying counts. In real deconvolution maps, counts may not be directly observed; this example shows why a fraction correlation by itself is not evidence of biological antagonism.

A useful diagnostic is to ask what is held fixed and what the fractions divide by. If reliable total abundance information is available, inspect it alongside the fractions. If only estimated compositions are available, report conclusions as relative shifts and avoid translating them into absolute cell gains or losses. Also inspect whether a negative pattern is dominated by one or two locations, or changes markedly when a different cell type is included in the represented total.

Zeros, Assumptions, and Practical Choices

Log-ratios require positive components because \(\log(0)\) is undefined. A zero can mean that a type is truly absent, that it was not detected, or that an estimation or reporting procedure returned zero. Those meanings are not interchangeable. A structural absence may call for a model that respects that absence; a detection-related zero may require a measurement model or a justified replacement strategy. Adding a small constant without checking its consequences can make the result depend strongly on the chosen constant.

Worked Example: Checking Sensitivity to a Zero Replacement

Suppose a hypothetical location has estimated fractions \((\hat{p}_A,\hat{p}_B,\hat{p}_C)=(0,0.20,0.80)\). A simple illustrative replacement adds \(\epsilon\) to each fraction and then renormalizes. Because renormalization multiplies every adjusted component by the same constant, the adjusted \(A\)-to-\(B\) ratio is \(\epsilon/(0.20+\epsilon)\).

With \(\epsilon=0.01\), the ratio is \(0.01/0.21=0.04762\), and the log-ratio is \(\log(0.04762)=-3.045\). With \(\epsilon=0.001\), the ratio is \(0.001/0.201=0.004975\), and the log-ratio is \(\log(0.004975)=-5.303\). The change is substantial even though only the replacement value changed.

This calculation is a sensitivity warning, not a recommendation to use either replacement. A defensible analysis should explain what the zero represents, state the chosen handling method, and assess whether substantive conclusions change under plausible alternatives. When zeros are common, methods designed for zero-containing compositions or a model of the underlying counts may be more appropriate.

A log-ratio comparison also relies on the cell types and denominator being meaningful for the question. If the target types are absent from the fitted composition, or if fractions were normalized over a changing subset, the resulting contrast may answer a different question than intended. Deconvolution estimates carry uncertainty as well; treating estimated fractions as exact can understate uncertainty in downstream comparisons. The earlier material on uncertainty in spatial deconvolution and reference mismatch is relevant when assessing these sources of uncertainty.

Choosing a Summary and Avoiding Overinterpretation

Raw fractions are often useful for maps and descriptive summaries: they show each type's share at each spot in familiar units from zero to one. But direct correlation or separate regression of every fraction can obscure the constraint and yield interpretations that depend on the chosen denominator. Log-ratio contrasts instead make the relative comparison explicit and can be easier to interpret when the scientific question names a pair or balance of cell types. A count-scale model can be preferable when counts and exposure or total abundance are meaningfully available, because it can address absolute quantities rather than only shares.

These approaches are not interchangeable. A log-ratio result cannot recover absolute abundance without additional information, and a count model needs a defensible account of sampling and total exposure. A raw-fraction result is not necessarily wrong, but it must be described as a change in share. For spatial data, any inferential approach must also account for spatial dependence and uncertainty in the deconvolution estimates as appropriate.

  • Check closure: verify which components are included and whether fractions sum to one at each location.
  • State the estimand: distinguish a change in share, a log-ratio change, and a change in absolute abundance.
  • Inspect zeros and denominators: document zero handling and test sensitivity to plausible choices.
  • Respect spatial structure: nearby locations may provide dependent information, even after transforming the fractions.
  • Avoid causal language: a negative fraction association does not by itself show competition or inhibition between cell types.
Key takeaway: Spatial fractions are constrained shares, not independent measurements of absolute abundance. Use log-ratio contrasts for explicit relative comparisons, and treat correlations among fractions as potentially shaped by closure.

Check Your Understanding

Try each question, then compare your reasoning with the solutions.

  1. At every location, two fractions satisfy \(p_B=1-p_A\). If \(p_A\) varies across locations, what is the correlation between the fractions, and what does that correlation establish?
  2. A location has fractions \(p_A=0.30\) and \(p_B=0.15\). Calculate the log-ratio contrast for \(A\) relative to \(B\) and interpret its sign.
  3. In a regional comparison, the mean log-ratio difference east minus west is \(\log(0.5)\). What does exponentiating this difference mean?
  4. Why can adding a small constant to zeros be problematic in a log-ratio analysis?
  5. Name one reason why a spatial analysis of log-ratios should not automatically treat all spots as independent.

Solutions. (1) The correlation is \(-1\), because the fractions are exact complements. It establishes a mathematical tradeoff in the shares, not biological competition. (2) The contrast is \(\log(0.30/0.15)=\log(2)=0.6931\). It is positive, so the fraction of \(A\) is twice the fraction of \(B\) at that location. (3) The east-to-west ratio of geometric-mean \(A\)-to-\(B\) ratios is \(\exp(\log(0.5))=0.5\); the relative ratio in the east is half that in the west. (4) The log-ratio can change substantially with the chosen constant, as the worked example demonstrates, so conclusions may reflect the replacement choice rather than the data. (5) Nearby spots can have spatial dependence, so treating them as independent can misrepresent uncertainty.

Clinical Biostats