Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Recognizing Reference Distribution Shift

Cell-Type Annotation and Its Uncertainty · Tutorial 346 of 700

Recognizing Reference Distribution Shift

Learn practical diagnostics for query–reference distribution shift and how to interpret its consequences for cell-type label probabilities.

Intermediate 12 min read

What You'll Learn

  • Define reference and query distributions for cell features and classifier scores.
  • Distinguish covariate, class-prior, and conditional distribution changes.
  • Compare aligned feature summaries and score distributions with appropriate caveats.
  • Separate changes in cell-type composition from within-type feature shifts.
  • Explain why distribution mismatch is a warning about probability transport, not proof that labels are wrong.
  • Identify common sources of misleading comparisons, including preprocessing differences and donor-level dependence.

Why Compare Query and Reference Distributions?

A cell-type classifier learns from a reference data set and is then applied to query cells. Even when the query cells receive plausible labels, their measured features may differ systematically from the reference. The difference may reflect tissue, biological condition, platform, preprocessing, cell-type composition, or some combination. Comparing distributions is a way to detect such mismatch and to ask whether probabilities learned in the reference are likely to remain informative in the query.

A distribution difference is a diagnostic signal, not a verdict. A query can have a different overall feature distribution simply because it contains different proportions of otherwise familiar cell types. Conversely, similar overall distributions do not guarantee that the relationship between features and labels is unchanged. Interpretation therefore depends on what is being compared and on how the query was collected and processed.

Definition: Let \(X\) denote the features supplied to a classifier and \(Y\) the cell-type label. The reference distribution describes \(X\) and \(Y\) in the data used to fit or validate the classifier; the query distribution describes them in the cells to be annotated. Reference distribution shift is a difference between these distributions that may affect how well the reference model’s predictions transfer to the query.

A feature may be a normalized expression value, a set of gene-expression measurements, or a representation constructed from them. A classifier may also produce a vector of label probabilities or scores. Comparing both features and scores can be useful: feature comparisons help identify where the inputs differ, while score comparisons show how the fitted model responds to the query. Neither comparison alone establishes that the model is wrong.

What Kind of Distribution Has Changed?

Three distinctions help organize the diagnosis. A change in the marginal feature distribution, \(P(X)\), means that query cells as a group have different feature values from reference cells. This is often called covariate shift. A change in the label proportions, \(P(Y)\), is a class-prior shift. A change in the feature–label relationship, \(P(Y\mid X)\), means that the same measured features no longer imply the same label probabilities. The last change is sometimes called conditional or concept shift.

These patterns can occur together. For example, a different tissue may contain new cell states, alter expression within familiar types, and change the proportions of types. A platform difference can shift measured expression even when the underlying biology is comparable. A condition can alter a marker gene within one cell type, changing how informative that gene is for classification. Observing a shifted \(P(X)\) does not, by itself, tell us which explanation applies.

The distinction matters for probabilities. If only \(P(X)\) changes while \(P(Y\mid X)\) stays the same, the reference conditional probabilities remain valid in principle, although a model may perform poorly in feature regions rarely seen during training. If \(P(Y\mid X)\) changes, reference probabilities need not describe the query. A difference in \(P(Y)\) can also change probabilities, even if the class-conditional feature distributions remain stable.

Key result: A query–reference difference in observed features is evidence of distribution mismatch, but it does not identify its cause or prove that \(P(Y\mid X)\) changed. Treat reference label probabilities as transportable only to the extent that the relevant feature–label relationship and measurement process remain sufficiently comparable.

Comparing Features and Scores

Begin by ensuring that the comparison is meaningful. Query and reference features should use the same genes, scale, normalization, and model input definition. A difference caused by using unnormalized counts in one data set and normalized values in the other is not evidence of biological mismatch. Likewise, a model score comparison is interpretable only when the same fitted classifier and score definition are applied to both sets.

For individual features, inspect distribution plots and compare robust summaries such as medians and interquartile ranges, as well as means and standard deviations when those summaries are useful. A standardized mean difference can provide a scale-free descriptive comparison. If the reference and query means are \(\bar{x}_R\) and \(\bar{x}_Q\), and their standard deviations are \(s_R\) and \(s_Q\), one descriptive version is

$$ d=\frac{\bar{x}_Q-\bar{x}_R}{\sqrt{(s_Q^2+s_R^2)/2}}. $$

The sign shows the direction of the difference, and the magnitude expresses it in units of the average within-group standard deviation. It is not a test statistic here, and there is no universal cutoff at which a shift becomes consequential. For high-dimensional features, examine a prespecified set of biologically or technically relevant features, or summaries of a representation used by the classifier; selecting only the largest observed differences can exaggerate their apparent importance.

For classifier outputs, compare the distributions of class probabilities, top scores, and possibly the margin between the largest and second-largest class scores. A shift toward lower top scores or smaller margins can indicate that query cells are less clearly supported by the reference model. It does not show that the model is calibrated in the query, and a high score is not proof of correctness. Score distributions should be read alongside feature comparisons and knowledge of the sampling design.

Worked Example: A Feature Is Shifted in the Query

Suppose a normalized expression feature has mean \(0.80\) and standard deviation \(0.60\) in a hypothetical reference sample, and mean \(1.35\) and standard deviation \(0.70\) in a hypothetical query sample. Assume both values were produced with the same gene set and preprocessing.

The descriptive standardized difference is

$$ d=\frac{1.35-0.80}{\sqrt{(0.60^2+0.70^2)/2}} =\frac{0.55}{\sqrt{(0.36+0.49)/2}} =\frac{0.55}{\sqrt{0.425}} \approx 0.844. $$

Thus, the query mean is about \(0.844\) average within-group standard deviations higher than the reference mean for this feature. This flags a potentially relevant difference, but does not identify whether it arises from cell composition, biology, or measurement. The distribution plots and comparisons within reasonably supported cell groups would help assess those possibilities. This calculation alone does not establish that any label probability is wrong.

Worked Example: Comparing Classifier Scores

A hypothetical classifier is run unchanged on held-out reference cells and query cells. For a particular label, the top-label probability has median \(0.82\) in 1,000 reference cells and \(0.61\) in 800 query cells. In the reference, 80 cells have a top-label probability below \(0.50\); in the query, 232 do.

The corresponding fractions below \(0.50\) are

$$ \frac{80}{1000}=0.080=8.0\%, \qquad \frac{232}{800}=0.290=29.0\%. $$

The query distribution has a lower median and a larger fraction of low top-label probabilities. That is evidence that the model is less decisive on these query cells under this score definition. It could reflect feature mismatch, different biological states, or greater ambiguity in the query; the summaries do not distinguish among these causes. The score values also do not establish the fraction of incorrect labels without suitable query labels or other validation evidence.

Separate Composition From Within-Type Differences

A whole-sample feature comparison can be driven by cell-type composition even when each type has the same feature distribution in both data sets. The overall mean is a weighted average of the type-specific means. If type \(k\) has proportion \(\pi_k\) and feature mean \(\mu_k\), the overall mean is \(\sum_k \pi_k\mu_k\). A change in \(\pi_k\) can therefore shift the overall mean while all the \(\mu_k\) values remain unchanged.

Worked Example: A Mean Shift Caused by Composition

Consider a hypothetical feature measured in two cell types. Type A has mean \(2\) units and type B has mean \(8\) units in both the reference and query. The reference is \(80\%\) type A and \(20\%\) type B; the query is \(40\%\) type A and \(60\%\) type B.

The reference overall mean is

$$ \bar{x}_R=0.80(2)+0.20(8)=1.6+1.6=3.2\text{ units}. $$

The query overall mean is

$$ \bar{x}_Q=0.40(2)+0.60(8)=0.8+4.8=5.6\text{ units}. $$

The overall mean differs by \(5.6-3.2=2.4\) units even though neither type’s feature mean changed. The difference is entirely explained by the stipulated change in composition. In practice, reference-based labels used to define groups can themselves be uncertain, so within-label comparisons should be interpreted cautiously rather than treated as definitive evidence of a biological mechanism.

A useful diagnostic is therefore to compare overall distributions and, where there is adequate support, distributions within relevant cell groups or strata. If an overall shift largely disappears within groups, composition is a plausible contributor. If a shift remains within groups, it may reflect a condition effect, platform effect, unmodeled state variation, or a mismatch in the annotation. Grouping by predicted labels is not a fully independent check: prediction errors can hide or create apparent within-group patterns.

Why Shift Can Affect Label Probabilities

A classifier’s probability output is learned from the reference relationship between features and labels. To see why it may not transfer, consider the special case of class-prior shift: assume that the class-conditional feature distributions \(P(X\mid Y)\) are unchanged, but the label proportions differ. Bayes’ rule gives the query posterior as

$$ P_Q(Y=k\mid X=x) = \frac{P_R(Y=k\mid X=x)\,\pi_{Q,k}/\pi_{R,k}} {\sum_j P_R(Y=j\mid X=x)\,\pi_{Q,j}/\pi_{R,j}}, $$

where \(\pi_{R,k}=P_R(Y=k)\) and \(\pi_{Q,k}=P_Q(Y=k)\). The relationship follows by writing \(P_Q(Y=k\mid x)\propto P_Q(x\mid Y=k)P_Q(Y=k)\), substituting the unchanged class-conditional distribution, and using \(P_R(Y=k\mid x)\propto P_R(x\mid Y=k)P_R(Y=k)\). This adjustment requires the stated stability assumption and the query class proportions; a marginal feature shift alone does not justify applying it.

More generally, calibration in a reference population means that predicted probabilities agree with observed frequencies under that reference sampling distribution. It does not automatically guarantee the same agreement in a query population. A query shift may change which cells receive a given score or may move cells into feature regions with little reference support. Thus a distribution comparison informs how cautious to be about probability interpretation; it does not supply a universal correction.

Diagnostics, Comparisons, and Failure Modes

1
Check comparability.
Confirm matching features, normalization, transformations, and score definitions before interpreting differences.
2
Inspect feature and score distributions.
Use plots and descriptive summaries to locate differences, rather than relying on a single overall metric.
3
Assess composition and strata.
Ask whether changes in cell-type proportions explain an overall feature shift; compare within groups only where there is adequate support.
4
Interpret probability transport cautiously.
State what the diagnostics suggest and what they cannot establish about query label correctness or calibration.

A formal two-sample test can supplement these checks, but a small p-value is not a measure of practical importance. With many cells, even a subtle difference may be detected; with correlated cells from a small number of donors, treating every cell as an independent replicate can overstate the evidence. Report the scale and direction of differences, and account for the sampling structure when making inferential claims. Descriptive plots and summaries are often more useful for locating a mismatch than a single significance test.

Univariate comparisons are easy to interpret but may miss shifts in combinations of features. Multivariate distances can summarize more dimensions, but their values depend on the representation, scaling, and distance definition. Neither approach diagnoses the biological cause on its own. A practical comparison uses complementary evidence: feature summaries, score distributions, known design information, and validation where labels are available.

Common failure modes include comparing incompatible preprocessing outputs, interpreting a composition-driven difference as within-cell expression change, and treating a low classifier score as proof of a novel cell type. The reverse error is also possible: apparently similar score distributions do not prove that query labels are reliable. A reference model can make confident predictions in a shifted setting. The central limitation is that unlabeled query distributions generally cannot reveal the true query relationship \(P(Y\mid X)\) by themselves.

Common mistake: “The query feature distribution differs from the reference, so the classifier’s label probabilities are invalid.” A difference does not establish that conclusion: it may be caused by composition, and \(P(Y\mid X)\) may still be stable. The correction is to use the mismatch as a warning, investigate its source and relevance, and avoid claiming query calibration without appropriate evidence.

Check Your Understanding

Answer each question, then compare with the brief solutions.

  1. A query has a shifted overall gene-expression mean. Name two explanations that do not require a change in expression within each cell type.
  2. In one sentence, distinguish a change in \(P(X)\) from a change in \(P(Y\mid X)\).
  3. Why does a lower median top-label probability in the query not directly estimate the query misclassification rate?
  4. What assumption is needed for the class-prior adjustment formula, and why is a marginal feature shift alone insufficient?
  5. Why can a two-sample test across thousands of cells give misleading inferential reassurance if the query comes from only a few donors?

Solutions. (1) The cell-type proportions may differ, or the measurement and preprocessing process may differ. (2) \(P(X)\) describes how common feature values are; \(P(Y\mid X)\) describes label probabilities at given feature values. (3) A score is not an observed correctness indicator, and its relation to correctness in the query has not been established. (4) The class-conditional feature distributions \(P(X\mid Y)\) must be stable, and query class proportions must be known or estimated; a marginal shift does not identify whether these conditions hold. (5) Cells from the same donor are not independent replicates, so cell-level testing can understate uncertainty about donor-to-donor variation.

Clinical Biostats