Tutorials › Pharmacometric Workflows and Reproducible Modeling › Choosing Residuals for Standard Diagnostics

Automating Diagnostics and Reports · Tutorial 285 of 399

Choosing Residuals for Standard Diagnostics

Compare common residual definitions and choose the quantity that matches each diagnostic display and modeling question.

Intermediate 12 min read

What You'll Learn

  • Distinguish population predictions, individual predictions, and their raw residuals.
  • Calculate individual weighted residuals from observation-level residual variance.
  • Explain the purpose and limitations of conditional weighted residuals.
  • Match residual quantities to population-fit, individual-fit, and residual-distribution displays.
  • Identify metadata and implementation details needed to make residual reports reproducible.

Why Residual Choice Matters

A residual is not a single universal quantity. It is an observation compared with a prediction, possibly scaled to account for variability, and the prediction itself may represent the population or a particular individual. A plot can therefore appear to show poor fit when it actually uses a residual intended for a different question—or appear reassuring because the residual has been normalized in a way that hides the distinction.

For standard diagnostics, the key choice is whether the display is assessing the population model or the fit after using individual-specific information. That choice determines which prediction and residual are appropriate. The display should also identify its residual definition, scale, and source; labels such as “weighted residual” alone may not be sufficient because implementations can differ.

Predictions and Raw Residuals

Let \(y_{ij}\) be the observed dependent-variable value for individual \(i\) at observation \(j\). Write the model prediction as \(f_{ij}(\theta,\eta_i)\), where \(\theta\) denotes population parameters and \(\eta_i\) denotes individual random effects. A population prediction, often called PRED, sets the random effects to their typical value, conventionally zero. An individual prediction, often called IPRED, uses an estimate \(\hat{\eta}_i\) for that individual.

Definition: The population raw residual is \(y_{ij}-\mathrm{PRED}_{ij}\). The individual raw residual is \(y_{ij}-\mathrm{IPRED}_{ij}\). These are differences on the response scale and retain the units of the observed variable.

Population raw residuals include discrepancies due to both individual deviations from the typical prediction and unexplained observation-level error. Individual raw residuals compare the observation with a prediction informed by that individual’s data; they are not an independent assessment of population fit. In particular, estimating \(\hat{\eta}_i\) using the same observations being plotted can make individual predictions track those observations more closely.

A common observation model is \(y_{ij}=f_{ij}(\theta,\eta_i)+\epsilon_{ij}\), with \(E(\epsilon_{ij}\mid\eta_i)=0\) and conditional variance \(R_{ij}\). The variance may depend on the predicted response—for example, under a proportional error model—or differ across observations. Thus, raw residuals with the same magnitude need not represent the same degree of discrepancy.

Worked Example: Population and Individual Raw Residuals

Suppose a hypothetical concentration observation is \(y=12.0\) mg/L. The population prediction is 9.0 mg/L, and the individual prediction is 11.2 mg/L. Calculate both raw residuals.

Population raw residual: \(12.0-9.0=3.0\) mg/L. The observation is 3.0 mg/L above the typical population prediction.

Individual raw residual: \(12.0-11.2=0.8\) mg/L. The observation is 0.8 mg/L above the prediction using the estimated individual effect.

The smaller individual residual does not, by itself, show that the population model predicts concentrations well. The individual prediction uses information about this subject; the population prediction does not.

Weighted Residuals and Their Assumptions

A weighted residual expresses a discrepancy relative to its expected variability. In the simplest case, if a prediction is treated as fixed and the residual has mean zero and known variance \(V_{ij}\), its standardized form is the raw residual divided by \(\sqrt{V_{ij}}\). The result is dimensionless. If the model and variance are correct, this standardized quantity has mean zero and variance one under those conditions.

$$ r_{ij}^{\mathrm{std}} = \frac{y_{ij}-\hat{y}_{ij}}{\sqrt{V_{ij}}} $$

The denominator must match the residual being standardized. For an individual weighted residual (IWRES), the numerator is typically \(y_{ij}-\mathrm{IPRED}_{ij}\), and the denominator is based on the observation-level residual variance at the individual prediction. Under an additive error model with standard deviation \(\sigma\), this denominator is \(\sigma\). Under a proportional error model with standard deviation \(\sigma f_{ij}\), it depends on the predicted response. The exact variance formula should follow the fitted observation model.

Definition: An individual weighted residual (IWRES) is an individual residual scaled by the observation-level residual variability specified by the model. In a simple independent-error case, \(\mathrm{IWRES}_{ij}=(y_{ij}-\mathrm{IPRED}_{ij})/\sqrt{R_{ij}}\). Software may use a more detailed calculation, so the report should record the implementation and variance convention.

A population weighted residual (often abbreviated WRES) is intended to scale a discrepancy associated with population predictions. However, “WRES” is not a guarantee of one universal formula: implementations can differ in how they calculate the variance used for weighting, including their treatment of random effects and model linearization. Do not silently substitute the observation-level residual variance for a marginal predictive variance, or assume two packages’ WRES columns are interchangeable. Record the exact software-defined quantity and its calculation.

Conditional weighted residuals (CWRES) are designed to assess population-model discrepancies while accounting for the conditional structure induced by individual random effects. In nonlinear mixed-effects models their calculation generally uses a conditional approximation or linearization; it is not simply the individual raw residual divided by a residual standard deviation. Under a correctly specified model and the method’s approximation conditions, CWRES are intended to be approximately centered at zero and scaled to unit variance. That reference behavior is approximate, not a guarantee that every finite-sample set of CWRES will look normally distributed.

Important distinction: IWRES describe deviations from individual predictions scaled by observation-level residual error. CWRES are population-oriented conditional weighted residuals intended to account for the model’s conditional structure. A CWRES should not be relabeled IWRES, or vice versa, merely because both are dimensionless.

Scaling a Residual: A Short Justification

Suppose \(e=y-\hat{y}\), with \(E(e)=0\) and \(\operatorname{Var}(e)=V>0\), where the prediction is treated as fixed for this calculation. Define \(z=e/\sqrt{V}\). Then

$$ E(z)=\frac{E(e)}{\sqrt{V}}=0, \qquad \operatorname{Var}(z)=\frac{\operatorname{Var}(e)}{V} =\frac{V}{V}=1. $$

This explains why standardization helps compare discrepancies across observations with different variances. It also shows the assumptions behind the simple result: the variance must be correctly specified, positive, and appropriate for the error being scaled; the residual must be centered under the model; and the prediction’s estimation must not invalidate the calculation. In a fitted mixed-effects model, predictions and individual effects are estimated, and observations within an individual may be conditionally related. The simple calculation therefore motivates weighting but does not establish that every software residual is exactly standard normal.

Worked Example: Calculating an Individual Weighted Residual

For a hypothetical observation, \(y=8.4\) mg/L and IPRED is 7.6 mg/L. Under the fitted proportional error model, the residual standard deviation at this prediction is 0.76 mg/L. Calculate the simple IWRES and interpret its scale.

The individual raw residual is \(8.4-7.6=0.8\) mg/L. The appropriate standardization uses the stated observation-level standard deviation:

$$ \mathrm{IWRES}=\frac{8.4-7.6}{0.76} =\frac{0.8}{0.76} \approx 1.053. $$

The IWRES is about 1.05, with no units. It means the observation is approximately 1.05 residual standard deviations above its individual prediction under this calculation. It does not mean there is a 1.05 probability of error, and it is not a population-level residual.

Which Residual Belongs in Which Display?

Choose the residual according to the question the display is designed to address, and label the prediction axis separately from the residual. A reliable diagnostic specification states the target (population or individual), residual definition, scaling rule, and any transformation or approximation.

Diagnostic displayPreferred quantityWhat the pairing represents
Observed values versus PREDObserved values and population predictionsAgreement between observations and typical population predictions
Observed values versus IPRED or individual fit panelObserved values and individual predictionsFit after using individual-specific estimates
Population residual versus predictionCWRES, or a precisely defined population WRESPopulation-oriented discrepancies on a standardized scale
Individual residual profileIWRES, with IPRED or observation context as specifiedIndividual deviations scaled by residual error
Residual distribution or normal-quantile displayA stated standardized residual, commonly CWRES for population assessmentWhether the selected residuals are compatible with their reference distribution

These are choices of quantity, not claims that a particular plot has a universal interpretation. For example, plotting IWRES answers a different question from plotting CWRES even if the axes and units look identical. For an observed-versus-prediction display, show the observed values and the appropriate prediction directly; do not replace that display with a residual plot and call it equivalent.

Worked Example: Selecting Residuals for a Report Panel

A hypothetical report has two panels. Panel A compares each observed concentration with the typical population prediction. Panel B shows how closely the model follows observations after estimating each subject’s random effects. The available output contains DV, PRED, IPRED, IWRES, and CWRES. Select the appropriate quantities.

Panel A: Use DV and PRED for the observed-versus-population-prediction display. If the report also includes a standardized population residual display, use CWRES when available and appropriate, or use the software’s documented WRES only after specifying its definition. IWRES is not a substitute for a population residual.

Panel B: Use DV and IPRED to display individual fits. For a residual profile assessing the remaining observation-level discrepancies, use IWRES. Its denominator must be the model’s appropriate observation-level residual scale. The report should retain subject and observation identifiers so the points can be traced to their source records.

The distinction is substantive: Panel A assesses the typical prediction, whereas Panel B assesses a prediction informed by subject-specific estimates. A small residual in Panel B cannot be presented as evidence that Panel A has the same level of fit.

Diagnostics, Failure Modes, and Alternatives

Before generating a standardized residual display, check that observations, predictions, and residuals refer to the same record and response scale. Confirm that the residual denominator is finite and positive, that the residual uses the intended prediction, and that missing or failed calculations have not been silently converted to zero. A reported residual with a missing prediction, a nonpositive variance, or an incompatible transformation is not interpretable as a valid standardized residual.

When population residuals are unexpectedly much smaller than individual residuals, or vice versa, first verify the definitions and joins rather than concluding that one model component has failed. Check whether one column is raw and another standardized, whether the denominator includes the intended error components, and whether one quantity was calculated on a transformed response scale. Record whether the residual is conditional or population-oriented, and whether its calculation depends on an approximation.

  • Raw residuals retain the response units and are easy to interpret in magnitude, but are not directly comparable across observations with different residual variability.
  • IWRES scale individual deviations using observation-level residual error and are useful for individual-fit assessment, but use predictions informed by the individual’s data.
  • CWRES target population-model assessment with conditional structure accounted for approximately; their construction is more involved and implementation-dependent.
  • WRES may be convenient when produced by the chosen software, but the name alone does not fully specify the calculation.

No standardized residual repairs a misspecified model, sparse information, or poor prediction support. Standardization can also make a plot look comparable while concealing that residuals were computed under different definitions or on different scales. For automated reports, store the residual type, prediction type, variance convention, software or calculation method, and response transformation with the diagnostic data. This makes subsequent comparisons reproducible and helps distinguish a change in model behavior from a change in residual calculation.

Common Mistake

Wrong reasoning: “IWRES and CWRES are both weighted residuals, so either can be used in any residual panel.” This ignores which prediction each quantity uses and what variability it represents.

Correction: Match the quantity to the diagnostic target. Use population predictions for population prediction displays, individual predictions for individual fit displays, and name the standardized residual explicitly. If the software’s WRES definition is not known, consult and record that definition rather than treating the abbreviation as self-explanatory.

Key takeaway: Select residuals by target, not by column availability. Raw residuals preserve response units; IWRES scale deviations from individual predictions; CWRES are designed for population-oriented conditional assessment. Document the exact computation and pairing in every diagnostic report.

Check Your Understanding

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

  1. An observation is 15 mg/L, PRED is 12 mg/L, and IPRED is 14 mg/L. Calculate both raw residuals and state which is population-oriented.
  2. A residual is 0.6 mg/L and its applicable observation-level standard deviation is 0.3 mg/L. What is the simple standardized residual?
  3. Why is IWRES not interchangeable with CWRES in a population diagnostic display?
  4. A report labels a column only “WRES.” Name two details that should be recorded before interpreting it.

Solutions. (1) The population raw residual is \(15-12=3\) mg/L; the individual raw residual is \(15-14=1\) mg/L. The first is population-oriented. (2) \(0.6/0.3=2.00\), or two residual standard deviations above the prediction under the stated calculation. (3) IWRES is based on an individual prediction and observation-level residual scaling, whereas CWRES is intended for conditional population assessment and can use a different calculation. (4) Record the software or algorithm defining WRES and the variance or weighting convention; also record which prediction and response scale it uses.

Clinical Biostats