Tutorials › Pharmacometric Workflows and Reproducible Modeling › Interpreting Residuals Versus Predictions

Automating Diagnostics and Reports · Tutorial 287 of 399

Interpreting Residuals Versus Predictions

Learn to construct residual-versus-prediction plots and interpret their patterns as diagnostic evidence of bias, changing variability, or distinct groups.

Intermediate 10 min read

What You'll Learn

  • Define and calculate raw residuals for a prediction plot, with the sign interpreted in context.
  • Check that the plotted residual and prediction come from compatible model outputs.
  • Recognize curved patterns, changing residual spread, and clusters.
  • Compare residual variability across prediction ranges using sample standard deviations.
  • Distinguish diagnostic clues from proof of a particular model failure.
  • Identify how scale, sparse data, and overlapping points can mislead interpretation.

Why Plot Residuals Against Predictions?

A model can produce predictions that look reasonable overall while systematically missing in part of the prediction range. A residual-versus-prediction plot makes that possibility visible by placing each prediction on the horizontal axis and its corresponding residual on the vertical axis. The plot is useful for asking two related questions: does the average prediction error change with the predicted value, and does the error’s spread change?

In a pharmacometric analysis, a prediction might be a predicted concentration in mg/L. The residual must be calculated from an observed concentration and a prediction on a compatible scale. For example, a concentration residual in mg/L should not be plotted against a prediction expressed as a log concentration unless that combination is intentional and clearly labelled. The pattern is a diagnostic clue, not a test that identifies a unique cause.

Definition: For observation \(i\), let \(y_i\) be the observed response and \(\hat{y}_i\) the corresponding model prediction on the response scale. The raw residual is \(e_i=y_i-\hat{y}_i\). A residual-versus-prediction plot places \(\hat{y}_i\) on the horizontal axis and \(e_i\) on the vertical axis. The horizontal reference line is \(e_i=0\), where observation and prediction agree.

With this sign convention, a positive residual means the observation exceeds the prediction, so the model underpredicted that observation. A negative residual means the observation is below the prediction, so the model overpredicted it. The residual’s units are the response’s units: if \(y_i\) is a concentration in mg/L, then \(e_i\) is also in mg/L.

Conditions for a Useful Plot

Before interpreting the pattern, verify that the plotted pairs are correctly assembled. Each point must match one observed response to the prediction used to calculate that point’s residual. The prediction and residual should refer to the same observation, response variable, record, and scale. If the chosen residual is based on a population prediction, the horizontal axis should use that corresponding population prediction; if the residual is based on an individual-level prediction, use that prediction instead. Mixing these definitions can create a pattern that reflects inconsistent processing rather than model behavior.

Under a correctly specified conditional mean model, the expected residual at a given set of predictors is zero when the prediction represents the conditional mean: \(E(Y_i\mid \text{predictors})=\hat{y}_i\) in the idealized case where that mean is known. A useful residual plot therefore should not show a systematic change in its center across the prediction range. If constant conditional variance is also assumed, the residual spread should be roughly similar across that range. These are diagnostic expectations, not guarantees that every finite sample will look perfectly patternless. In practice, predictions are estimated, data may be sparse, and observations within a subject may be related.

1
Choose a consistent prediction-residual pair.
Confirm that each residual is calculated from the same kind of prediction that will appear on the horizontal axis, and that both quantities use compatible response scales.
2
Draw and label the axes.
Put predictions on the horizontal axis and residuals on the vertical axis. Include units, the residual definition, and a horizontal zero line.
3
Inspect the center, spread, and grouping.
Look for systematic curvature, a change in vertical spread, or distinct clusters. Check whether sparse regions or overlapping points could obscure the pattern.
4
Describe evidence, then consider explanations.
State what the plotted points show before suggesting a model or data-processing explanation. A visual pattern alone does not establish its cause.

Worked Patterns in the Plot

Worked Example: Curvature in the Residual Center

Suppose a hypothetical concentration analysis gives six predictions and observed concentrations as shown below. Both are in mg/L. Calculate each raw residual, then interpret the pattern.

Prediction \(\hat{y}_i\) (mg/L)Observed \(y_i\) (mg/L)Residual \(e_i=y_i-\hat{y}_i\) (mg/L)
1.01.40.4
2.02.20.2
3.02.4-0.6
4.03.4-0.6
5.05.20.2
6.06.40.4

For the prediction of 1.0 mg/L, \(e_i=1.4-1.0=0.4\) mg/L; for the prediction of 3.0 mg/L, \(e_i=2.4-3.0=-0.6\) mg/L. The other residuals follow from the same subtraction. As predictions increase, residuals are positive at the low end, negative in the middle, and positive again at the high end. Positive residuals indicate underprediction, while negative residuals indicate overprediction. This U-shaped center suggests that the model may miss systematic curvature in the conditional mean. It does not, by itself, identify what model change would address that pattern.

A curved pattern is a change in the average residual across predictions, not simply the presence of individual positive and negative values. In a dense plot, a smooth trend can help reveal the center, but it should not replace examination of the points. The key diagnostic question is whether residuals systematically tend to one side of zero over part of the prediction range.

Worked Example: Increasing Residual Spread

A second hypothetical analysis has four residuals in a low-prediction range and four in a high-prediction range. All residuals are in mg/L. The low-range residuals are \(-0.3,\ 0.2,\ -0.1,\ 0.2\); the high-range residuals are \(-1.0,\ 1.0,\ -0.8,\ 0.8\). Compare their sample standard deviations as a descriptive check of the spread.

Both sets have mean zero. For the low range, the sum of squared deviations from the mean is \(0.09+0.04+0.01+0.04=0.18\ \text{(mg/L)}^2\). With \(n=4\), the sample standard deviation is

$$ s_{\text{low}}=\sqrt{\frac{0.18}{4-1}} =\sqrt{0.06} =0.244948\ldots \approx 0.2449\ \text{mg/L}. $$

For the high range, the sum of squared deviations is \(1.00+1.00+0.64+0.64=3.28\ \text{(mg/L)}^2\). Therefore,

$$ s_{\text{high}}=\sqrt{\frac{3.28}{4-1}} =\sqrt{1.093333\ldots} =1.045626\ldots \approx 1.046\ \text{mg/L}. $$

The high-range sample standard deviation is about \(1.046/0.2449=4.27\) times the low-range value. If the plotted residuals also visibly fan out as predictions increase, this is evidence of greater residual variability in the high-prediction range. The calculation is descriptive: four residuals per range are too few to establish a stable variance relationship, and the values need not be independent.

A funnel shape refers to changing vertical spread, whether the spread grows or shrinks with predictions. It is distinct from curvature: the residual center can stay near zero while the spread changes. A pattern can also show both features. A wider funnel may be compatible with a response-scale variance that increases with the mean, but it can also arise from influential observations, sparse high predictions, or distinct groups that have been combined.

Worked Example: Two Residual Clusters

Suppose a hypothetical plot contains points from two data-processing batches. In batch A, residuals are \(-0.5,\ -0.4,\ -0.6\) mg/L at predictions of 2.0, 3.0, and 4.0 mg/L. In batch B, residuals are \(0.4,\ 0.5,\ 0.3\) mg/L at predictions of 2.2, 3.2, and 4.2 mg/L. The prediction ranges overlap, but the residuals form separate negative and positive bands.

The mean residual in batch A is

$$ \bar{e}_A=\frac{-0.5-0.4-0.6}{3} =\frac{-1.5}{3} =-0.5\ \text{mg/L}. $$

The mean residual in batch B is

$$ \bar{e}_B=\frac{0.4+0.5+0.3}{3} =\frac{1.2}{3} =0.4\ \text{mg/L}. $$

On average, the model overpredicts in batch A and underpredicts in batch B. Pooling all six points gives a mean residual of \((-1.5+1.2)/6=-0.05\) mg/L, which is close to zero and conceals the opposing patterns. The clusters warrant checking whether the groups differ in a relevant way or whether records were processed consistently. The plot alone cannot tell which explanation is correct.

Why These Patterns Matter—and What They Cannot Establish

A short justification explains why a changing residual center is diagnostically important. Let the true conditional mean at predictor values \(x\) be \(m(x)=E(Y\mid x)\), and let the model predict \(f(x)\). The expected raw residual at those predictor values is

$$ E(Y-f(x)\mid x)=E(Y\mid x)-f(x)=m(x)-f(x). $$

Thus, if the model’s prediction differs systematically from the true conditional mean, the expected residual is not zero at those predictor values. If that discrepancy varies with prediction, the residual center can curve or shift across the horizontal axis. Likewise, when the conditional variance \(Var(Y\mid x)\) changes with prediction, the residual spread can change. A plotted pattern is only a finite-sample visual indication of these differences; it does not reveal the true conditional mean or variance exactly.

Residual-versus-prediction plots answer a different question from other diagnostic views. Residuals versus time can reveal patterns ordered by time, whereas the prediction plot organizes observations by predicted response. Observed-versus-prediction plots display agreement in the response scale; residuals make departures from agreement easier to inspect around a zero reference. Changing from a population prediction to an individual-level prediction can also change the pattern, so the prediction definition must be reported. These plots complement one another rather than serving as interchangeable versions of the same check.

The plot has important limits. Points may overlap, especially when predictions take repeated values. A small number of observations at either end of the prediction range can make a funnel or curve look stronger than the data support. Repeated observations from the same subject may not provide independent evidence, and an extreme point can dominate the apparent pattern. The residual scale also matters: raw residuals are expressed in response units, so the spread may naturally grow with the response even when a different error model is appropriate. A residual plot is not a formal test of a variance assumption, and a pattern does not prove a particular scientific mechanism.

Common Mistakes and Practical Checks

  • Reversing the sign interpretation. With \(e_i=y_i-\hat{y}_i\), a negative residual means the observation is below the prediction, so the model overpredicted. A positive residual means the model underpredicted.
  • Pairing incompatible quantities. A residual based on one prediction definition should not be paired with a different prediction definition. Confirm the source fields and calculations before reading the plot.
  • Calling every scatter a pattern. Finite samples will not fall exactly on zero. Look for a systematic center shift, changing spread, or separated bands rather than isolated departures alone.
  • Treating a funnel as proof of one cause. It may reflect changing variability, sparse data, influential observations, or mixed groups. Report the visible feature and investigate plausible explanations separately.
  • Ignoring units and scale. Label the residual definition, response units, prediction units, and any transformation. A raw residual on a transformed response scale has a different interpretation from one on the original scale.
Key takeaway: Read the residual center and spread separately. Curvature or a persistent shift from zero suggests prediction bias across part of the prediction range; a funnel suggests changing residual variability; clusters suggest that pooled behavior may conceal distinct patterns. Each is evidence to investigate, not a diagnosis by itself.

Check Your Understanding

Answer each question using the residual definition \(e_i=y_i-\hat{y}_i\). Solutions follow the questions.

  1. An observation is 4.6 mg/L and its prediction is 5.0 mg/L. What is the residual, and does the model overpredict or underpredict?
  2. Residuals tend to be negative at low predictions and positive at high predictions. Interpret the direction of the model’s errors at each end.
  3. What does a funnel-shaped residual-versus-prediction plot suggest, and why does the plot not establish the cause?
  4. A plot shows two residual bands in an overlapping prediction range. Give one reason to investigate the grouping and one reason not to claim a cause from the plot alone.

Solutions. 1. \(e_i=4.6-5.0=-0.4\) mg/L. The observation is below the prediction, so the model overpredicts by 0.4 mg/L. 2. Negative residuals at low predictions indicate overprediction at the low end; positive residuals at high predictions indicate underprediction at the high end. This systematic change in the residual center is consistent with bias across the prediction range. 3. A funnel suggests that residual spread changes with prediction. It does not identify whether the cause is a variance-model mismatch, sparse data, influential observations, or another feature of the data. 4. Separate bands may indicate that pooled residual behavior hides distinct groups, so checking relevant metadata or processing consistency is sensible. The plot does not identify which group difference or process produced the bands, so the cause requires additional evidence.

Clinical Biostats