Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Pearson Residuals as Variance-Stabilized Features

Highly Variable Genes and Feature Selection · Tutorial 116 of 700

Pearson Residuals as Variance-Stabilized Features

Learn how Pearson residuals standardize gene counts against a fitted mean–variance model, how residual variability supports gene ranking, and what extreme values can reveal about model fit.

Intermediate 10 min read

What You'll Learn

  • Define Pearson residuals for counts under a negative-binomial mean–variance model.
  • Derive why a correctly standardized residual has mean zero and variance one when model parameters are known.
  • Calculate per-cell residuals and compare genes using their across-cell variability.
  • Distinguish Pearson-residual rankings from negative-binomial deviance rankings.
  • Diagnose residual patterns that may indicate misspecification rather than informative biological variation.

Why Standardize Counts Before Ranking Genes?

A raw count difference does not have the same meaning at every expression level. A difference of three molecules can be substantial for a gene whose expected count is near one, but modest for a gene whose expected count is near one hundred. A gene-ranking method should therefore account for both the fitted mean and the expected variability at that mean.

Pearson residuals do this by dividing each observed-minus-fitted count difference by its model-based standard deviation. Across cells, unusually variable residuals can identify genes whose observed variation exceeds what the fitted count model predicts. This is a way to construct features on a common scale; it does not make counts normally distributed or prove that a high-ranked gene is biologically important.

Definition and Model

Let \(Y_{ig}\) be the observed count for gene \(g\) in cell \(i\), and let \(\hat{\mu}_{ig}\) be its fitted mean under a count model. For a negative-binomial model, use the dispersion parameterization \(\operatorname{Var}(Y_{ig}\mid\text{model})=\mu_{ig}+\phi_g\mu_{ig}^2\), where \(\phi_g\geq 0\). A fitted mean may account for cell-specific library size through an offset and may include other modeled covariates. The Pearson residual uses the fitted mean and variance.

Definition: The Pearson residual for cell \(i\) and gene \(g\) is \(r_{ig}=(Y_{ig}-\hat{\mu}_{ig})/\sqrt{\hat{\mu}_{ig}+\hat{\phi}_g\hat{\mu}_{ig}^{\,2}}\). Its numerator is the count deviation from the fitted mean; its denominator is the model-based standard deviation of that count. When \(\hat{\phi}_g=0\), the variance reduces to the Poisson variance \(\hat{\mu}_{ig}\).

The model is conditional on whatever offsets and covariates were used to fit it. Interpreting residuals as standardized deviations assumes that the mean structure is adequate, the dispersion captures the relevant conditional variability, and the observations are sufficiently independent for the intended comparison. In single-cell data, these are working assumptions, not guarantees. Estimating parameters from the same data also means residuals need not have exactly zero mean or unit variance.

Why the Standardization Works

The basic justification follows from the first two conditional moments. If the model parameters were known and the model were correct, then \(E(Y_{ig}\mid\text{model})=\mu_{ig}\) and \(\operatorname{Var}(Y_{ig}\mid\text{model})=V_{ig}\), where \(V_{ig}=\mu_{ig}+\phi_g\mu_{ig}^2\). Thus:

$$ E\left[\frac{Y_{ig}-\mu_{ig}}{\sqrt{V_{ig}}}\middle|\text{model}\right] =\frac{E(Y_{ig}\mid\text{model})-\mu_{ig}}{\sqrt{V_{ig}}}=0, \qquad \operatorname{Var}\left(\frac{Y_{ig}-\mu_{ig}}{\sqrt{V_{ig}}}\middle|\text{model}\right) =\frac{\operatorname{Var}(Y_{ig}\mid\text{model})}{V_{ig}}=1. $$

This is the sense in which Pearson residuals are variance-standardized. It is a statement about their first two moments under a correct model, not a claim that each residual is normally distributed. Counts can be discrete and strongly skewed, especially at low means. Fitting parameters, filtering cells, or misspecifying the mean or variance can also change the residual distribution.

For a gene, a simple variability score is the sample variance of its residuals across \(n\) cells: \(s^2_{r,g}=\frac{1}{n-1}\sum_{i=1}^{n}(r_{ig}-\bar r_g)^2\), where \(\bar r_g=\frac{1}{n}\sum_i r_{ig}\). Larger values mean greater residual spread relative to the fitted model. Another possible summary is the mean squared residual, \(Q_g=\frac{1}{n}\sum_i r_{ig}^2\). Unlike the centered variance, \(Q_g\) also reflects a nonzero average residual, so a ranking based on it can mix systematic mean misfit with cell-to-cell variability. Inspect the residual mean as well as the spread.

Worked Example: Standardizing One Count

Suppose a hypothetical cell has an observed count of \(8\) for a gene. Its fitted mean is \(\hat{\mu}=1\), and its fitted negative-binomial dispersion is \(\hat{\phi}=0.2\). Calculate the Pearson residual.

The fitted variance is \(\hat{\mu}+\hat{\phi}\hat{\mu}^{2}=1+0.2(1)^2=1.2\). Therefore:

$$ r=\frac{8-1}{\sqrt{1.2}}=\frac{7}{\sqrt{1.2}}\approx 6.390. $$

The count is about \(6.390\) fitted standard deviations above its expected value. This is a large positive residual and a reason to investigate the observation and model. It is not, by itself, a p-value, a probability that the model is false, or proof of a biological outlier.

Using Residual Variability to Rank Genes

To compare genes, first calculate each cell–gene residual using that gene's fitted mean and dispersion. Then summarize how much the residuals vary across cells. A high residual-variance score indicates that the gene varies more across the observed cells than its fitted mean–variance relationship predicts. If the score is low, the observed differences are broadly compatible with that relationship.

The interpretation depends on the model. For example, if a biological covariate was included in the mean, residual variability describes variation remaining after accounting for that covariate; it does not summarize the total biological variation. Conversely, omitting a relevant cell group or technical effect can inflate residual spread. A ranking is therefore a model-dependent ordering, not a model-free property of a gene.

Worked Example: Comparing Residual Variance for Two Genes

Consider four hypothetical cells. For both genes, suppose the fitted mean in every cell is \(1\) and the fitted dispersion is \(0.2\), giving a fitted variance of \(1.2\). Gene A has counts \((0,1,2,1)\); gene B has counts \((0,0,4,0)\). Calculate their Pearson residuals and sample variances.

For either gene, the residual is \((Y-1)/\sqrt{1.2}\). Write \(a=1/\sqrt{1.2}\approx0.9129\). Gene A has residuals \((-a,0,a,0)\), with mean zero. Its residual sum of squares is \(a^2+a^2=2/1.2=1.6667\), so:

$$ s^2_{r,A}=\frac{1.6667}{4-1}\approx 0.5556. $$

Gene B has residuals \((-a,-a,3a,-a)\), also with mean zero. Its residual sum of squares is \((1+1+9+1)a^2=12/1.2=10\), so:

$$ s^2_{r,B}=\frac{10}{4-1}\approx 3.333. $$

Gene B has the larger residual-variance score in these data. Its count of \(4\) creates a much larger standardized deviation from the fitted mean than the corresponding counts for gene A. This small example illustrates the calculation, not a universal cutoff or a claim that gene B is biologically meaningful.

Extreme Residuals and Model Diagnostics

An extreme residual can arise because a cell genuinely expresses a gene unusually strongly or weakly. It can also arise because the fitted mean is too small, the dispersion is underestimated, a relevant covariate is missing, or the observation reflects a technical problem. The residual alone cannot distinguish these explanations.

Check residuals in context rather than treating a large absolute value as an automatic exclusion rule. Useful checks include:

  • Plotting residuals against fitted means or library size to look for systematic trends.
  • Checking whether residuals are consistently shifted above or below zero for a gene or group of cells.
  • Examining whether a few extreme values dominate a gene's variability score.
  • Comparing residual patterns across known batches or biological groups that were not included in the fitted mean.
  • Checking whether the dispersion estimates and mean–variance trend are plausible for the range of expression being analyzed.

For example, residual spread that increases systematically with fitted mean can indicate that the variance model does not adequately capture the mean–variance relationship. A cluster of positive residuals in one batch may point to an omitted batch effect, but it could also reflect a true difference between the cells in that batch. The data collection and study design are needed to evaluate the alternatives.

At low fitted means, the discreteness and asymmetry of counts are particularly important: a residual of a given magnitude does not necessarily have the same tail probability across genes or cells. Pearson residuals are not automatically standard normal, so normal-theory cutoffs or p-values should not be assigned to them without an appropriate distributional argument. Extreme values can be flagged for review, but their interpretation requires diagnostics and biological context.

How Pearson Residuals Differ From Other Rankings

Negative-binomial deviance, the subject of the earlier material on negative-binomial deviance for feature ranking, also compares observed counts with fitted means. A deviance residual is based on the likelihood loss relative to a saturated model; a Pearson residual is based directly on the signed difference divided by the fitted standard deviation. Both depend on the count model, but they weight discrepancies differently, so their gene rankings need not agree.

Dispersion-based rankings instead summarize excess variability relative to a mean–variance trend. Pearson-residual rankings express deviations on the scale of fitted standard deviations and can retain cell-level information before a gene summary is formed. Neither approach removes model dependence. A high score under either method can reflect omitted structure as well as the variation of interest.

Worked Example: Separating a Large Residual From a High Variance Score

Suppose, hypothetically, a gene has residuals \((-0.2,-0.2,-0.2,6.0)\) across four cells. The large residual may attract attention, but calculate the mean and sample variance to see how the single observation affects the summary.

The mean is \(\bar r=(-0.2-0.2-0.2+6.0)/4=1.35\). The squared deviations from this mean are \((-1.55)^2\), \((-1.55)^2\), \((-1.55)^2\), and \(4.65^2\). Their sum is \(3(2.4025)+21.6225=28.83\). Therefore:

$$ s^2_r=\frac{28.83}{4-1}=9.610. $$

The sample variance is large, but it is driven by one cell, and the positive average residual also signals possible mean misfit. The correct conclusion is that this gene merits diagnostic review; the score alone does not establish whether the cell is erroneous, the model is inadequate, or the value is meaningful biological variation.

Common Pitfalls and Limitations

  • Assuming variance stabilization means normality. Dividing by the fitted standard deviation standardizes the model-based variance; it does not make discrete counts normally distributed.
  • Treating every extreme residual as an error. A large residual can reflect a real signal, a technical issue, or a misspecified mean or variance. Investigate rather than automatically discard it.
  • Interpreting residual variance as biological variability alone. The score includes any unmodeled technical or biological structure, and its meaning depends on which covariates were included.
  • Ignoring a nonzero residual mean. A score based on squared residuals can be high because of a systematic shift, not only cell-to-cell spread. Inspect both the mean and centered variance.
  • Reading a ranking as a significance test. Residual scores order genes under a fitted model; they do not supply a p-value or a probability that a gene is important.

Pearson residuals are useful when the goal is to compare count deviations on a scale that accounts for expected mean-dependent variance. Their strengths—simple standardization and a direct connection to the fitted variance—come with a central limitation: a misspecified model can create misleading residuals and rankings. Model checks are part of interpreting the score, not an optional step after it.

Check Your Understanding

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

  1. If a fitted mean is \(4\), a fitted dispersion is \(0.1\), and the observed count is \(7\), calculate the Pearson residual.
  2. Under a correct model with known parameters, why does the Pearson residual have variance one?
  3. Why can a high mean squared residual score reflect mean misfit as well as variability?
  4. A gene has one very large positive residual and otherwise small residuals. What is one appropriate diagnostic response?

Solutions. For question 1, the fitted variance is \(4+0.1(4)^2=5.6\), so \(r=(7-4)/\sqrt{5.6}=3/\sqrt{5.6}\approx1.268\). For question 2, the residual variance is the count variance divided by the fitted variance: \(V/V=1\), provided the model is correct and its parameters are known. For question 3, mean squared residuals are measured around zero, so a nonzero average residual contributes to the score; centered variance measures spread around the residual mean instead. For question 4, check the cell’s data and residual patterns against fitted mean, library size, and relevant covariates; a large residual alone does not establish whether the observation is erroneous or biologically meaningful.

Clinical Biostats