Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Diagnosing Dispersion and Mean-Variance Fit

Differential Expression With Pseudobulk and Mixed Models · Tutorial 505 of 700

Diagnosing Dispersion and Mean-Variance Fit

Use negative-binomial variance formulas, gene-wise dispersion trends, and standardized residual summaries to assess whether pseudobulk variance modeling is adequate.

Advanced 12 min read

What You'll Learn

  • State the negative-binomial mean–variance model used for pseudobulk gene counts.
  • Explain why dispersion is assessed both within genes and across genes.
  • Calculate a gene-wise Pearson residual summary and interpret its scale.
  • Compare observed gene-wise dispersion estimates with a fitted mean–dispersion trend.
  • Identify design, covariance, and replication issues that can make dispersion diagnostics misleading.
  • Distinguish a diagnostic flag from evidence that a gene is an outlier or a model is definitively wrong.

Why Diagnose Dispersion?

A pseudobulk model must represent more than the expected count for each gene in each sample. It must also represent how much counts vary around those expectations. If the assumed variance is too small, standard errors can be underestimated and gene-level tests can be poorly calibrated; if it is too large, estimates may be less precise than necessary. Dispersion diagnostics ask whether the model’s variance assumptions are plausible for the observed pseudobulk data, both for individual genes and across genes with different expression levels.

The focus here is the fit of the variance model, not a decision rule for declaring genes differentially expressed. A conspicuous residual pattern is a reason to investigate the model and data; it does not, by itself, establish a biological effect, prove that a sample is erroneous, or justify removing a gene.

The Mean–Variance Model

Let \(Y_{gj}\) be the pseudobulk count for gene \(g\) in sample \(j\), and let \(\mu_{gj}\) be its fitted mean. A common negative-binomial model uses the NB2 variance parameterization:

Definition: Under the NB2 model, conditional on the modeled predictors and any modeled random effects, \(Y_{gj}\) has mean \(\mu_{gj}\) and variance \(\mu_{gj}+\alpha_g\mu_{gj}^{2}\), where \(\alpha_g\geq 0\) is the dispersion for gene \(g\). When \(\alpha_g=0\), the variance reduces to the Poisson variance \(\mu_{gj}\). Larger \(\alpha_g\) means greater conditional variation beyond the Poisson component.
$$ \operatorname{Var}(Y_{gj}\mid \text{modeled effects}) =\mu_{gj}+\alpha_g\mu_{gj}^{2} $$

The mean model must account for the study design and relevant sample-level variables. For example, a log-link model may include a library-size offset \(\log L_j\), a condition effect, and other design terms. A dispersion diagnostic is meaningful only relative to the fitted means and the covariance structure the model specifies. A misspecified mean, omitted batch term, or unmodeled repeated-measures correlation can appear as extra residual variation.

In a mixed model, the conditional variance formula does not by itself describe all marginal variability across samples. Random effects induce covariance and can add marginal variation. Therefore, residuals must be interpreted against the fitted model’s covariance structure: simple Pearson residuals are most direct for independent observations, while mixed-model diagnostics should account for the covariance implied by the random effects. The earlier material on residual diagnostics for pseudobulk models provides the general role of residual checks; here the emphasis is how their variation relates to dispersion and expression level.

Gene-Wise Residual Variation

For independent observations under the NB2 model, a Pearson residual for a gene and sample is the observed-minus-fitted count divided by its model-based standard deviation:

$$ r_{gj}= \frac{Y_{gj}-\hat{\mu}_{gj}} {\sqrt{\hat{\mu}_{gj}+\hat{\alpha}_g\hat{\mu}_{gj}^{2}}} $$

If the fitted variance is adequate, these standardized residuals should not systematically be much more variable than the model predicts. One compact summary is the Pearson residual sum of squares divided by residual degrees of freedom:

$$ Q_g=\frac{1}{df_g}\sum_j r_{gj}^{2} $$

Here \(df_g\) is the residual degrees of freedom used for that gene’s fitted model. In a simple model with \(n\) independent observations and \(p\) estimated mean parameters, a rough reference is \(df_g=n-p\). In more complex models, residual degrees of freedom and the appropriate residual calculation depend on the fitting method. Under a well-calibrated model and adequate information, \(Q_g\) is often around 1, but it is not an exact universal cutoff: small samples, estimated parameters, leverage, and dependence affect its reference distribution.

For a mixed model, a covariance-aware version uses residuals transformed so that their fitted covariance is approximately the identity matrix. If \(\mathbf{e}_g\) is the residual vector and \(V_g\) is its fitted covariance matrix, a whitening matrix \(W_g\) satisfies \(W_gV_gW_g^{T}=I\); the transformed residuals are \(W_g\mathbf{e}_g\). Their squared magnitude can then be compared with an appropriate residual degrees-of-freedom reference. Treating correlated observations as independent can make a residual-variation summary misleading.

Worked Example: Calculating a Pearson Residual Summary

Suppose a hypothetical independent-group analysis has six pseudobulk samples for one gene. The fitted means are \(10,20,15,25,30,20\), and the observed counts are \(12,15,18,22,38,15\). Assume the fitted dispersion is \(\hat{\alpha}_g=0.05\), and the mean model has \(p=2\) estimated parameters. For illustration, the observations are treated as independent and the residual degrees of freedom are \(6-2=4\).

For the first sample, the fitted variance is \(10+0.05(10^2)=15\), so its squared Pearson residual is \((12-10)^2/15=4/15=0.2667\). Applying the same calculation to the other samples gives:

$$ \begin{aligned} \sum_j r_{gj}^2 &=\frac{(12-10)^2}{15} +\frac{(15-20)^2}{40} +\frac{(18-15)^2}{26.25}\\ &\quad+\frac{(22-25)^2}{56.25} +\frac{(38-30)^2}{75} +\frac{(15-20)^2}{40}\\ &=0.2667+0.6250+0.3429+0.1600+0.8533+0.6250\\ &=2.8729. \end{aligned} $$

Thus \(Q_g=2.8729/4=0.7182\). This summary is below 1, so these residuals do not suggest that the fitted variance is too small for this gene. With only six observations, however, the summary is imprecise; it does not establish that the variance model is correct, nor is it a formal goodness-of-fit test.

Assessing the Mean–Dispersion Trend

Across genes, dispersion estimates are often noisy, especially when there are few biological replicates. A mean–dispersion plot places a measure of average expression on one axis and gene-wise dispersion estimates on the other. A fitted trend summarizes how dispersion typically changes with expression level. The trend may be approximately flat or may decrease as mean expression rises, depending on the data and estimation procedure; it should be estimated rather than assumed to have a particular shape.

The diagnostic question is whether individual gene estimates show large, persistent departures from the trend, or whether residual variation is systematically related to mean expression. Such patterns can indicate that a common variance trend is inadequate, that a subset of genes has unusual variability, or that an aspect of the mean or covariance model is not represented. Because individual dispersion estimates are noisy, many workflows stabilize or shrink them toward a trend. A trend or stabilized estimate is a modeling aid, not a claim that every gene has exactly the same dispersion.

Worked Example: Reading a Mean–Dispersion Trend

Consider hypothetical fitted dispersions for three genes at increasing average expression. At mean counts 5, 20, and 80, their gene-wise estimates are 0.12, 0.08, and 0.05, while a smooth trend gives 0.10, 0.07, and 0.04. A fourth gene at mean count 20 has estimated dispersion 0.24, compared with the same trend value of 0.07.

For the fourth gene, the ratio of its estimate to the trend is \(0.24/0.07=3.429\). This is a substantial descriptive departure. It is a flag to inspect the gene’s sample-level residuals and the adequacy of its fitted mean and covariance structure. It is not, on its own, a p-value, proof of a biological subgroup, or grounds for excluding the gene. The first three estimates lie relatively close to their corresponding trend values, but that agreement also does not prove the trend is correct.

A Moment-Based Justification

The form of the NB2 variance explains why dispersion is assessed relative to the mean rather than by raw variance alone. If observations have a common mean \(\mu\) and variance \(\mu+\alpha\mu^2\), solving for \(\alpha\) gives the population moment relation below. Replacing population moments with estimates yields a rough diagnostic estimate; in a regression, fitted means differ across samples and parameter estimation must be accounted for, so this calculation is illustrative rather than a substitute for the model’s estimator.

$$ \alpha=\frac{\operatorname{Var}(Y)-\mu}{\mu^2} $$

For example, if hypothetical counts have mean 20 and residual variance 52, the moment relation gives \(\alpha=(52-20)/20^2=32/400=0.0800\). The Poisson component accounts for variance 20, and the additional variance component is 32. This calculation also shows why raw variance cannot be compared fairly across genes with different means: even when \(\alpha\) is identical, the \(\alpha\mu^2\) contribution grows quadratically with the mean.

Worked Example: Comparing Raw Variance With Dispersion

Suppose two hypothetical genes have fitted mean counts 10 and 40, and both follow the NB2 model with \(\alpha=0.10\). Their expected variances are:

$$ \begin{aligned} \operatorname{Var}(Y_1)&=10+0.10(10^2)=20,\\ \operatorname{Var}(Y_2)&=40+0.10(40^2)=200. \end{aligned} $$

The second gene has ten times the variance, yet both genes have the same dispersion. Calling the second gene “more overdispersed” from raw variance alone would confuse scale with dispersion. The relevant comparison is how observed variation relates to each gene’s mean-dependent fitted variance.

Practical Workflow, Alternatives, and Failure Modes

A disciplined diagnostic workflow checks the fitted assumptions before treating an unusual dispersion as a gene-specific property.

1
Check the model context.
Confirm that the gene’s design terms, sample offsets, and repeated-measures or random-effect structure reflect the data collection and analysis target.
2
Inspect gene-level residual variation.
Use residuals standardized against the variance and covariance actually fitted. Look for a broad excess or deficit, not just one large residual.
3
Compare dispersion with expression level.
Plot gene-wise estimates and the fitted mean–dispersion trend. Look for systematic structure and conspicuous departures, remembering that estimates are noisy.
4
Investigate before changing the model.
Check whether a pattern is tied to omitted design structure, few replicates, or a mean-model mismatch. Refit only with a defensible model change and compare conclusions.

The main alternatives make different assumptions. A Poisson model sets \(\alpha_g=0\) and is unsuitable when variation materially exceeds the Poisson variance. A negative-binomial model with one common dispersion is simpler but can miss gene-to-gene variability. Gene-wise dispersions are more flexible but can be unstable with limited replication. Trend-based or shrinkage approaches borrow information across genes to stabilize estimates while allowing departures; their quality depends on the trend being a useful summary. Robust standard errors can change uncertainty estimates under some forms of misspecification, but they do not make an incorrect mean or covariance model correct.

Several patterns deserve caution. A large \(Q_g\) for one gene may be driven by a single unusual count; it does not show that all samples for that gene are more variable. Broadly elevated residual variation across many genes may indicate a variance or covariance problem, but can also reflect inadequate mean modeling. A trend that bends sharply at the sparsely populated ends of the expression range may be driven by few genes. Finally, small numbers of biological replicates limit the precision of gene-wise dispersion estimates; many cells within a donor do not replace independent biological replication.

Do not use this diagnostic as a test for excess zeros, as a sample-influence analysis, or as a rule for identifying differentially expressed genes. Those questions require distinct checks. In particular, a dispersion departure should prompt investigation, not automatic exclusion: removing a gene or sample solely because it conflicts with the fitted model can bias inference.

Common mistake: “This gene has a larger raw count variance than another gene, so it is more overdispersed.” The correction is to compare observed variation with the mean-dependent variance, \(\mu+\alpha\mu^2\), and assess dispersion relative to expression level and the fitted covariance structure.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. Under an NB2 model, a gene has fitted mean 30 and dispersion 0.06. What is its fitted variance?
  2. A gene has mean 10 and observed residual variance 14. Using the moment relation, calculate its approximate dispersion.
  3. Why can two genes with different raw variances have the same dispersion?
  4. A gene has a large Pearson residual sum of squares divided by residual degrees of freedom. What can this indicate, and what does it not prove?
  5. Why should correlated repeated pseudobulk observations not be treated as independent when summarizing residual variation?

Solutions. (1) \(30+0.06(30^2)=30+54=84\) count-squared units. (2) \((14-10)/10^2=4/100=0.0400\). This is only a moment-based approximation. (3) The NB2 variance depends on both mean and dispersion; different means can produce different variances even when \(\alpha\) is equal. (4) It can flag variance underestimation or another model mismatch, but it does not prove a particular cause, identify a faulty sample, or establish that the gene should be removed. (5) Dependence changes the residual covariance and therefore the expected residual variation; a covariance-aware diagnostic is needed to avoid a misleading summary.

Clinical Biostats