Tutorials › Pharmacometric Workflows and Reproducible Modeling › Residual Diagnostics by Study or Occasion

Automating Diagnostics and Reports · Tutorial 290 of 399

Residual Diagnostics by Study or Occasion

Learn to build and interpret grouped residual plots that reveal study-, occasion-, or dosing-period-specific patterns hidden by pooled diagnostics.

Intermediate 12 min read

What You'll Learn

  • Define groups using study, occasion, or dosing-period labels in the diagnostic data.
  • Compare group-specific residual centers and spreads with pooled displays.
  • Use a weighted-mean decomposition to explain how opposing offsets can cancel.
  • Interpret grouped plots while accounting for sample size, residual scale, and repeated observations.
  • Distinguish useful visual diagnostics from claims that require further investigation.

Why Examine Residuals by Group?

A pooled residual plot can look acceptable even when residual behavior differs meaningfully across studies or occasions. For example, one study may have residuals predominantly above zero while another has residuals predominantly below zero. When both are combined, their average can be near zero, concealing the group-specific offsets. Conversely, a pooled plot may show broad scatter because one group is much more variable than the others.

Grouping residuals by study, occasion, or dosing period is a targeted diagnostic: it asks whether the residual pattern is similar across those defined subsets. It does not replace the standard residual-versus-time, residual-versus-prediction, or distributional displays. Rather, it adds the group label to the diagnostic question. The earlier material on residuals versus time, residuals versus predictions, residual distributions, and residual trends across covariates provides the relevant general plotting context.

Definition: A grouped residual diagnostic displays or summarizes residuals separately for observations assigned to a defined category, such as study, occasion, or dosing period. A residual is the observed value minus the corresponding model prediction; a standardized or normalized residual expresses that difference relative to an estimated error scale. Interpret grouped comparisons using the residual definition and scale selected for the diagnostic.

For a group comparison to be meaningful, observations must be assigned consistently, and the plotted residuals must be on a scale that supports comparison. If residuals are raw concentration differences and expected measurement variability differs greatly with concentration, a wider raw spread in one group may reflect that scale difference rather than worse model performance. Use the residual type chosen for the standard diagnostics and state its units or, for standardized residuals, that it is dimensionless and measured in standard-deviation units.

What Grouped Displays Can Reveal

Common displays include separate panels for each group or a single plot that uses distinct symbols or colors. A horizontal reference at zero helps assess residual location. When panels are compared, keep the vertical scale common: independently rescaled axes can make very different residual spreads appear similar. For a small number of groups, overlaid points can support direct comparison; for many groups, separate panels can reduce visual clutter. In either layout, show the number of observations when practical and avoid interpreting a few points as a stable group pattern.

Inspect at least three features within each group: whether residuals are centered near zero, whether their spread is broadly comparable, and whether there is a structure such as a sequence or cluster of positive or negative values. A grouped plot against time within an occasion can reveal a pattern that a single group mean cannot. Study labels can also identify differences in data collection or measurement context that merit investigation. These displays flag patterns; they do not, by themselves, establish their cause.

Why Pooling Can Conceal a Group Offset

Suppose the residuals are divided into groups indexed by \(g\). Let \(n_g\) be the number of residuals in group \(g\), \(N=\sum_g n_g\), and \(\bar{r}_g\) the group mean. The pooled mean is a weighted average of group means, with weights equal to the groups’ proportions of observations.

$$ \bar{r}=\frac{\sum_g n_g\bar{r}_g}{N} $$

This identity explains why a pooled center near zero does not guarantee that every group is centered near zero: positive and negative group means can cancel. There is a related decomposition for empirical variance. Define \(s_g^2\) here as the within-group variance using divisor \(n_g\), and define the pooled variance using divisor \(N\). Then:

$$ \frac{1}{N}\sum_g\sum_{i=1}^{n_g}(r_{ig}-\bar{r})^2 = \sum_g\frac{n_g}{N}s_g^2 + \sum_g\frac{n_g}{N}(\bar{r}_g-\bar{r})^2 $$

To justify the decomposition, write each deviation as \(r_{ig}-\bar{r}=(r_{ig}-\bar{r}_g)+(\bar{r}_g-\bar{r})\), square it, and sum within group. The cross-product sums to zero because \(\sum_i(r_{ig}-\bar{r}_g)=0\). The remaining terms are the weighted within-group variance and the weighted variation among group means. Thus, pooled spread combines within-group spread with between-group differences in location. A pooled spread alone cannot tell which component is responsible.

Worked Example: Opposing Study Offsets Cancel in the Pooled Mean

Consider hypothetical standardized residuals from two studies. Study A has \(1, 2, 1, 2\); Study B has \(-2, -1, -2, -1\). Each residual is dimensionless, in estimated error standard-deviation units. The groups have equal size, and the pooled mean is:

$$ \bar{r}=\frac{1+2+1+2-2-1-2-1}{8}=\frac{0}{8}=0 $$

That pooled center might seem reassuring, but the group means are \(\bar{r}_A=6/4=1.5\) and \(\bar{r}_B=-6/4=-1.5\). The positive and negative offsets cancel exactly. Within each group, deviations from its own mean are \(-0.5, 0.5, -0.5, 0.5\), so the within-group variance using divisor 4 is \(1/4=0.25\). The weighted between-group component is \(2.25\), since both group means are 1.5 units from the pooled mean. The pooled variance using divisor 8 is therefore \(0.25+2.25=2.50\), consistent with the direct calculation \((4+1+4+1+1+4+1+4)/8=20/8=2.50\).

The grouped display would show a clear study-specific shift that the pooled mean misses. This is a diagnostic signal to check study-specific data handling, measurement context, and model adequacy; it does not establish which explanation is responsible.

Worked Comparisons of Group Spread and Occasion Pattern

Worked Example: One Study Has Wider Residual Scatter

Suppose hypothetical standardized residuals are Study A: \(-1, 0, 1, 0\), and Study B: \(-2, 2, -2, 2\). Both group means equal zero. To compare sample standard deviations, use \(s=\sqrt{\sum_i(r_i-\bar{r})^2/(n-1)}\).

For Study A, the squared deviations sum to \(1+0+1+0=2\), so \(s_A=\sqrt{2/3}=0.8165\). For Study B, they sum to \(4+4+4+4=16\), so \(s_B=\sqrt{16/3}=2.309\). Both groups are centered at zero, but Study B has substantially wider scatter in this small hypothetical sample.

Pooling yields a mean of zero and a sample standard deviation of \(\sqrt{18/7}=1.604\), since the total squared deviation is \(2+16=18\) across eight observations. That single spread does not describe either group well: it is larger than Study A’s and smaller than Study B’s. The grouped plot therefore adds information even though there is no group mean offset. With only four observations per study, treat the spread difference as a prompt for review, not a precise estimate of a stable variance difference.

Worked Example: A Shift Appears in a Later Dosing Period

In a hypothetical dataset, four normalized residuals from an early dosing period are \(-0.5, 0, 0.5, 0\), while four from a later period are \(0.8, 1.0, 1.2, 1.0\). The early-period mean is \((-0.5+0+0.5+0)/4=0\). The later-period mean is \((0.8+1.0+1.2+1.0)/4=1.0\). The pooled mean is \(4/8=0.5\).

A pooled display would suggest a modest positive average, whereas the grouped display shows that the positive center is concentrated in the later period. The early residuals vary around zero; the later residuals cluster around one standard-deviation unit above zero. This pattern could be consistent with a period-related model or data issue, but a residual plot cannot determine the cause. Check the period definitions, predictions, and relevant data-processing steps before drawing a substantive conclusion.

Assumptions, Diagnostics, and Alternatives

Grouped residual plots are descriptive diagnostics, not tests that require independent observations or normally distributed residuals. Their interpretation nevertheless depends on several practical conditions:

  • Correct group assignment. Study, occasion, and dosing-period labels must refer to the intended observations. Verify coding and boundary rules, especially when occasions or periods are constructed from times.
  • Comparable residual meaning. Use a consistent definition across groups. If the error scale or transformation differs, explain how the residuals were made comparable; raw residual magnitudes may not be comparable across different units or scales.
  • Visible sample sizes and scales. Small groups give unstable impressions, and different vertical axis limits can disguise spread differences. Retain a shared scale for direct visual comparison.
  • Dependence is acknowledged. Repeated observations from the same individual are not necessarily independent. A sequence of positive residuals within one individual or occasion may carry different information from the same number of positive residuals scattered across independent individuals.

A useful diagnostic workflow is to first examine the pooled plot, then stratify by the label relevant to the question, compare centers and spreads on common axes, and finally investigate any persistent pattern in context. If the concern is a location shift, compare group centers; if it is variability, compare spreads. If the pattern is temporal, inspect the residuals in their time order within each group rather than relying only on a group summary.

The main alternative is to retain a pooled plot, which is simpler and can reveal broad overall problems but may hide group differences. Separate panels make group patterns easier to see, although many panels can become hard to compare. Overlaid groups facilitate direct comparison when there are few groups but can obscure points when they overlap. A numerical summary can complement either plot, but a summary alone loses ordering and local structure. Formal modeling or testing may be appropriate for a specific follow-up question, but a visual pattern is not itself a significance test and does not imply a causal group effect.

Common failures include drawing separate panels with independently scaled axes, interpreting an average near zero as evidence that all groups are well centered, and treating every visible group difference as proof of model failure. Another pitfall is to group by a label without checking how it was defined: a misclassified occasion can create an artificial pattern. Examine counts, units, residual type, and data assignments before interpreting the plot. Grouped diagnostics are also limited by sparse groups, influential observations, and correlations among repeated measurements; they cannot repair a misspecified model or establish why a pattern occurred.

Key takeaway: A pooled residual diagnostic describes the combined observations. Grouped diagnostics reveal whether location, spread, or structure differs by study, occasion, or dosing period. Compare like with like, use common scales, and treat a visible difference as a signal for investigation rather than a causal conclusion.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. Two equally sized studies have mean standardized residuals of \(1.2\) and \(-1.2\). What is the pooled mean, and what does it fail to show?
  2. Why should separate group panels generally use the same vertical axis limits?
  3. Four observations in a dosing period have residuals \(0, 1, 1, 2\). Calculate their mean and describe one limitation of interpreting it.
  4. A grouped plot shows one study with wider residual scatter but a similar center. Name one follow-up check and one reason not to conclude immediately that the model is worse in that study.

Solutions. (1) With equal group sizes, the pooled mean is \((1.2+(-1.2))/2=0\). It fails to show the opposite study-specific offsets, which cancel. (2) Common limits preserve visual comparability; independently scaled panels can make different spreads look alike. (3) The mean is \((0+1+1+2)/4=1\) standardized-residual unit. Four observations provide limited information, and repeated observations may not be independent, so the group mean is only a diagnostic signal. (4) Check residual definitions, data and study assignments, and whether the plotted residual scale is comparable across studies. A small sample or a few influential observations could produce wider apparent scatter, so the plot alone does not establish a stable difference in model performance.

Clinical Biostats