Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Residual Diagnostics for Donor-Aware Models

Biological Replication and Donor-Level Inference · Tutorial 470 of 700

Residual Diagnostics for Donor-Aware Models

Learn to use donor-level residual plots and cluster summaries to assess model fit, variance patterns, and potentially influential donors.

Advanced 12 min read

What You'll Learn

  • Define raw, standardized, conditional, and marginal residuals in donor-aware models.
  • Interpret residuals against fitted values, covariates, and donor identity.
  • Recognize patterns that suggest nonconstant variability or a misspecified mean model.
  • Distinguish unusual individual residuals from influential donor clusters.
  • Understand what cluster-robust standard errors do and do not address.
  • Apply a structured diagnostic workflow and explain its limitations.

Why Diagnose Residuals at the Donor Level?

A donor-aware model is intended to represent both the scientific relationship of interest and the dependence among observations from the same donor. Its diagnostics should therefore ask whether the fitted relationship is plausible across donors, not merely whether many cell-level residuals look small. A donor with many sampled cells can produce many residuals, but those cells do not constitute many independent biological replicates.

Residual diagnostics are descriptive checks on a specified model, not a guarantee that its assumptions are true. They can reveal patterns that merit investigation, such as a curved mean relationship, a donor with an unusual response, or variability that grows with the fitted mean. They cannot establish that a model is correct, and they should not be used as an automatic rule for deleting a donor.

Definition: For donor \(i\) and observation \(j\), let \(y_{ij}\) be the observed outcome and \(\hat{y}_{ij}\) its fitted value. A raw residual is \(e_{ij}=y_{ij}-\hat{y}_{ij}\). A donor-level residual summary may be a residual for a donor-level outcome, or a defined summary of the residuals within donor \(i\). Residuals are observed minus fitted, so positive residuals indicate outcomes above the fitted values.

Which Fitted Values and Residuals?

In a linear model, fitted values are generated by the model's estimated coefficients. In a mixed model, the choice of fitted value matters. A marginal fitted value uses the population-level fixed effects and averages over the random effects. A conditional fitted value also includes the estimated donor-specific random effect. The corresponding residuals answer different questions: marginal residuals show how observations depart from the population-level relationship, while conditional residuals show departures after accounting for the fitted donor-specific effect.

Conditional residuals can look relatively small because donor-specific effects were estimated using the same observations. In particular, estimated random effects are partially pooled toward the population mean, and the conditional residual pattern should not be read as if donor effects were known in advance. State which fitted values were used when presenting a diagnostic.

For models with one row per donor, residual diagnostics are directly examined at the donor level. For models with multiple observations per donor, inspect within-donor residual patterns as well as donor summaries. A large collection of cell-level residuals is not a substitute for assessing how the model performs across independent donors.

Key distinction: Cluster-robust standard errors address uncertainty in coefficient estimates under within-donor dependence, given appropriate conditions for the independent clusters and the mean model. They do not correct a misspecified mean relationship, make a problematic donor disappear, or ensure that fitted values capture the observed pattern.

A Justification for Leverage-Adjusted Residuals

Even under a correctly specified homoskedastic linear model, raw residuals do not all have the same variance. This matters when comparing their magnitudes. To see why, consider a donor-level linear model in matrix form, \(y=X\beta+\varepsilon\), with independent errors of mean zero and common variance \(\sigma^2\). The ordinary least-squares fitted values are \(Hy\), where \(H=X(X^\mathsf{T}X)^{-1}X^\mathsf{T}\), so the residual vector is \(e=(I-H)y\). Since \((I-H)X=0\), this becomes \(e=(I-H)\varepsilon\).

$$ \operatorname{Var}(e) =(I-H)\operatorname{Var}(\varepsilon)(I-H)^\mathsf{T} =\sigma^2(I-H) $$

The last equality uses the symmetry and idempotence of \(H\). Thus the variance of residual \(e_i\) is \(\sigma^2(1-h_{ii})\), where \(h_{ii}\) is the \(i\)th diagonal entry of \(H\), called leverage. A residual from a high-leverage donor can be smaller partly because the fit was influenced by that donor. Standardized or studentized residuals account for estimated scale and, in common linear-model diagnostics, leverage. Their exact form depends on the model and fitting method; a simple residual divided by an estimated standard deviation is not automatically a fully studentized residual.

This derivation also explains a basic caution: residuals are constrained by the fitting process. In a model with an intercept, their sum is zero, and in linear regression they are orthogonal to the included predictors. A zero average residual, by itself, is therefore not evidence that the model fits well.

Plots and Patterns to Examine

A useful diagnostic set begins with residuals plotted against fitted values and against important predictors. Under a well-specified mean relationship, residuals should fluctuate around zero without a systematic shape. A smooth curve, repeated sign changes, or a trend suggests that the fitted mean may be missing structure. A fan-shaped cloud, in which residual spread grows or shrinks across fitted values, suggests nonconstant variability.

Also inspect donor identity or donor-level summaries. A plot with donors labelled can reveal whether unusual residuals cluster in one donor, occur in donors with a particular covariate, or appear across many donors. A normal quantile plot can help identify strong departures from a normal error model when that assumption supports the chosen inference. With few donors, such a plot has limited resolution; it cannot certify normality.

Diagnostics should match the model. If the model allows donor-specific slopes, examine whether residual patterns remain across the predictor after those slopes are included. If repeated observations within donors have a meaningful order, inspect residuals against that order for systematic structure. Do not interpret a plot that treats cell-level residuals as independent evidence about between-donor variability.

Worked Example: Finding an Unusual Donor Residual

Suppose a hypothetical study has one outcome summary per donor, and a constant-mean model is fitted to six independent donors. The observed summaries, in arbitrary expression units, are \(4, 5, 5, 6, 7,\) and \(9\). The model assumes a common mean; for illustration, suppose the outcomes are independent across donors and have a common variance. A normal-error assumption would also be needed for exact normal-theory inference, but is difficult to assess with only six donors.

The fitted mean is \(36/6=6\) units. The raw residuals are therefore \(-2,-1,-1,0,1,\) and \(3\) units. Their sum is zero, as expected for a fitted model with an intercept. The residual sum of squares is \(4+1+1+0+1+9=16\) squared units. With one fitted mean, the residual degrees of freedom are \(6-1=5\), giving an estimated residual variance \(s^2=16/5=3.2\) squared units and \(s=\sqrt{3.2}=1.789\) units.

Dividing each raw residual by \(s\) gives approximately \(-1.118,-0.559,-0.559,0,0.559,\) and \(1.677\). The donor with outcome 9 has the largest positive residual: its observed summary is 3 units above the fitted mean. This is a reason to inspect that donor and the data contributing to its summary, not proof that the donor is erroneous or should be removed. With six donors, the estimated scale and distributional diagnostics are themselves uncertain.

Worked Example: A Fan-Shaped Variance Pattern

Consider eight hypothetical independent donors in a linear model with predictor \(x\), fitted relationship \(\hat{y}=2+2x\), and the following residuals. Each predictor value occurs twice, with residuals of equal magnitude and opposite sign.

\(x\)Fitted valueResiduals for the two donorsMean squared residual at \(x\)
02\(-0.2,\ 0.2\)0.04
14\(-0.4,\ 0.4\)0.16
26\(-0.8,\ 0.8\)0.64
38\(-1.6,\ 1.6\)2.56

The observed outcome is the fitted value plus the residual. For example, at \(x=3\), the outcomes are \(8-1.6=6.4\) and \(8+1.6=9.6\). At each predictor value the residuals sum to zero, so the residuals sum to zero overall and their product-sum with \(x\) is also zero. The displayed line is consequently consistent with the ordinary least-squares fit to these data.

The mean squared residual rises from \(0.04\) to \(2.56\), a factor of \(2.56/0.04=64\). The residuals are centred around zero, but their spread increases markedly with the fitted value. This pattern is evidence against constant residual variance. Eight donors are too few to establish a precise variance function, and the pattern alone does not identify its cause. A model-based variance specification may need review; cluster-robust standard errors can provide a different basis for uncertainty estimates under their conditions, but do not remove the visible pattern or repair the mean model.

Donor-Level Influence and Model Fit

An unusual residual and an influential donor are not the same thing. A residual measures a donor's discrepancy from the fitted outcome; influence asks how much the fitted result changes when that donor's information is removed or downweighted. A donor may have a large residual but little influence if it has low leverage, or a moderate residual but substantial influence if its covariates are unusual. Examine influence at the donor-cluster level: deleting individual cells while leaving their donor in the analysis does not answer whether the result depends on that donor.

Leave-one-donor-out coefficient comparisons are one practical diagnostic. They are sensitivity checks, not a formal test for whether a donor is valid. Interpret a change relative to the original estimate, its uncertainty, and the scientific scale of the effect. A donor can be biologically unusual and still belong to the target population.

Worked Example: One Donor Drives a Group Difference

Suppose a hypothetical study has three independent donors in each of two groups, with donor-level outcome summaries in arbitrary units. The control summaries are \(1,2,2\), and the treated summaries are \(2,3,9\). Consider the donor-weighted difference in group means, with the same weight for each donor. The equal donor weighting is part of this example's target; it is not an estimate weighted by cell count.

The control mean is \((1+2+2)/3=5/3=1.667\) units. The treated mean is \((2+3+9)/3=14/3=4.667\) units. The estimated difference is \(14/3-5/3=3\) units. The treated residuals around their group mean are \(2-14/3=-8/3\), \(3-14/3=-5/3\), and \(9-14/3=13/3\) units. The donor with outcome 9 has a conspicuously large residual.

Now omit that donor as a sensitivity check. The remaining treated mean is \((2+3)/2=2.5\) units, so the difference from the control mean is \(2.5-1.667=0.833\) units. The estimated difference changes by \(0.833-3=-2.167\) units. This indicates that the estimate is sensitive to that donor. It does not establish that the donor is an error, nor does it supply a new definitive estimate: there are now only two treated donors, and the uncertainty is substantial. The diagnostic conclusion is to investigate and report the sensitivity transparently.

Common Failure Modes and Alternatives

A useful diagnostic review considers what each finding does and does not imply:

  • Curved residual pattern: the mean model may be missing nonlinear structure or an interaction. A variance adjustment alone will not fix a wrong conditional mean.
  • Increasing or decreasing spread: the constant-variance assumption may be implausible. Consider whether the outcome scale, model variance structure, or an inference method appropriate to the design needs review.
  • Donor-specific cluster of residuals: check data processing, donor-level covariates, and the assumed donor structure. The pattern may reflect genuine heterogeneity rather than a mistake.
  • One large residual: investigate measurement, sample handling, and model fit, but do not delete a donor solely because it changes a result.
  • Apparent normality across thousands of cells: this can be misleading when cells from a donor are dependent. For population-level claims, the number of independent donors remains central.

Alternatives are complementary rather than interchangeable. Model-based residual plots check the fit and variance structure implied by a model. Cluster-robust standard errors can protect coefficient uncertainty against some forms of within-donor dependence when there are enough independent clusters and the mean model is appropriate; they do not diagnose or cure poor fit. Design-based inference relies on the assignment or sampling design rather than a full outcome distribution model, but still requires diagnostics relevant to its specified estimand and design. Leave-one-donor-out analysis measures sensitivity to particular clusters, while residual plots show patterns across fitted values or predictors.

These checks have important limits. With few donors, patterns are noisy and formal distributional tests have little power; a lack of a visible pattern is not proof of an assumption. Residuals are estimated quantities, affected by model fitting, and mixed-model residuals depend on whether predictions are conditional or marginal. Diagnostics also cannot verify that donors represent the population to which results are generalized. They should inform model review and transparent reporting, not become a search for a preferred result.

A Practical Diagnostic Sequence

1
Specify the fitted quantity.
Name the outcome, donor unit, model, and whether fitted values are marginal or conditional. Confirm that the residuals correspond to the estimand being interpreted.
2
Plot residuals against fitted values and predictors.
Look for curvature, trends, changing spread, and ranges where the model consistently over- or under-predicts.
3
Inspect donor structure.
Label donors or summarize within donor. Check whether patterns are concentrated in particular clusters and whether a donor has unusual covariates or leverage.
4
Assess sensitivity and limitations.
Use donor-level influence checks where relevant, compare the result with reasonable alternatives, and state how few donors limit diagnostic certainty.
Key takeaway: Residual diagnostics ask whether the fitted model leaves systematic structure across donors, predictors, or fitted values. Interpret residual size, variance patterns, and donor influence separately, and remember that a standard-error correction does not by itself make a poor-fitting model adequate.

Check Your Understanding

Answer each question, then compare with the brief solutions.

  1. In a model with a constant term, why is a zero sum of raw residuals not evidence that the model fits well?
  2. A donor has a moderate residual but an unusual predictor value. Why might it still be influential?
  3. In a fitted-value plot, residual spread grows as fitted values increase. What assumption is questioned, and what does a cluster-robust standard error not fix?
  4. In the group comparison example, calculate the treated mean and the group difference after excluding the donor with outcome 9.

Solutions. (1) Fitting the intercept makes residuals sum to zero by the least-squares normal equations, even if residuals show curvature, changing spread, or other systematic patterns. (2) A donor with unusual covariates can have high leverage, so its inclusion may substantially affect the fitted coefficients even if its residual is not especially large. (3) The pattern questions constant residual variance. A cluster-robust standard error may change uncertainty estimates under suitable conditions, but it does not repair a misspecified mean or remove the variance pattern. (4) The remaining treated mean is \((2+3)/2=2.5\) units. The control mean remains \(5/3=1.667\) units, so the difference is \(2.5-1.667=0.833\) units.

Clinical Biostats