Tutorials › Nonlinear Mixed-Effects Models (NLME) › Within-Subject Occasion Diagnostics

Goodness-of-Fit Diagnostics and Their Pitfalls · Tutorial 556 of 797

Within-Subject Occasion Diagnostics

Use within-subject residual and fit comparisons to identify occasion-specific patterns without confusing them with subject effects or time-dependent misfit.

Intermediate 11 min read

What You'll Learn

  • Define occasions and organize residual comparisons within subjects.
  • Interpret paired occasion contrasts and identify what cancels—and what does not.
  • Separate occasion-specific patterns from between-subject differences and overall time trends.
  • Check whether time support, residual scale, and sampling are comparable.
  • Recognize when plots suggest a pattern but cannot establish its cause.

Why Compare Occasions Within a Subject?

A model can fit the overall data reasonably well while describing one occasion poorly. For example, profiles from the same subject might be systematically underpredicted at a later visit, even if residuals pooled across all visits are centered near zero. Pooling can conceal this pattern because positive residuals from one occasion may cancel negative residuals from another. Comparing occasions within subjects helps reveal such shifts while holding constant stable characteristics of each subject.

An occasion is a prespecified, scientifically meaningful period or study segment within a subject, such as a dosing interval or a visit. The occasion definition should follow the design and analysis question; it should not be chosen after inspecting residuals to make a pattern appear stronger. Use residuals on a comparable scale, such as the same type of standardized residual at every occasion. A residual's sign indicates whether the observation is above or below its corresponding prediction, subject to the residual convention used.

Definition: A within-subject occasion diagnostic compares residuals or observed-versus-predicted patterns from two or more occasions belonging to the same subject. Its purpose is to assess whether misfit is systematically associated with occasion, while examining whether apparent differences instead reflect subject composition, sampling time, or other changes in data support.

The diagnostic is exploratory: a pattern can flag a model or data feature to investigate, but it does not by itself identify a cause. In particular, an occasion contrast is not automatically evidence for a biological period effect or a need for an occasion-specific random effect.

Organizing the Comparison

Keep subject identity visible. Useful displays include subject-specific residual-versus-time panels separated by occasion, paired summaries for each subject, and observed-versus-individual-prediction overlays for subjects with observations on multiple occasions. Within a subject, compare occasions over time regions represented on both occasions. Also inspect the number and timing of observations: an occasion with mostly early samples should not be treated as directly comparable to one with mostly late samples.

A simple descriptive decomposition clarifies what a paired comparison can and cannot remove. Let \(r_{ijk}\) denote a residual for subject \(i\), occasion \(k\), at observation \(j\), and let \(t_{ijk}\) be the relevant time. For interpretation, consider the schematic representation

$$ r_{ijk}=a_i+c_{ik}+g(t_{ijk})+\varepsilon_{ijk}. $$

Here \(a_i\) represents a stable subject-level residual tendency, \(c_{ik}\) an occasion-associated component, \(g(t)\) a shared time-related pattern, and \(\varepsilon_{ijk}\) remaining variation. This is a diagnostic bookkeeping device, not a claim that residuals necessarily follow this exact model or that the components can be identified from a plot. In particular, a stable tendency in residuals is not the same thing as a subject's pharmacokinetic random effect.

Write \(\bar r_{ik}\) for the mean residual among the observations available for subject \(i\) on occasion \(k\). Subtracting occasion means cancels a common \(a_i\), but the other terms need not cancel:

$$ \bar r_{i2}-\bar r_{i1} = (c_{i2}-c_{i1}) + \left\{\overline{g(t)}_{i2}-\overline{g(t)}_{i1}\right\} + \left(\bar\varepsilon_{i2}-\bar\varepsilon_{i1}\right). $$

The bars on \(g(t)\) and \(\varepsilon\) denote averages over the observations in the corresponding occasion. Thus, even if the occasion-associated components are equal, unequal time support or chance variation can produce a nonzero observed contrast. Similar sampling times can make a time contribution more comparable, but do not guarantee equality. Matching or stratifying by time can reduce this concern; it cannot remove all uncertainty or unmeasured differences.

Worked Comparisons

Worked Example: A Paired Occasion Pattern

Suppose three hypothetical subjects each have standardized residuals at two visits, with positive values meaning observations exceed predictions. The within-occasion means are: subject A, \(0.2\) at occasion 1 and \(0.8\) at occasion 2; subject B, \(-0.1\) and \(0.5\); subject C, \(0.3\) and \(0.9\). Assume the occasions have similar time support for these summaries, but not necessarily identical residual variation.

Calculate each paired contrast as occasion 2 minus occasion 1:

$$ \begin{aligned} d_A&=0.8-0.2=0.6,\\ d_B&=0.5-(-0.1)=0.6,\\ d_C&=0.9-0.3=0.6. \end{aligned} $$

All three contrasts are positive and equal to \(0.6\) standardized-residual units. The consistent direction is a reason to inspect occasion 2 more closely: its observations tend to lie above their predictions relative to occasion 1 in these subjects. The calculation does not prove an occasion effect. The paired contrast cancels a stable subject component in the schematic decomposition, but retains any differences in average time contribution and remaining variation. With only three subjects, it is also a small descriptive summary, not a general population conclusion.

Worked Example: An Apparent Shift Caused by Time Support

For one hypothetical subject, suppose residuals tend to increase by \(0.10\) standardized-residual units per hour over the displayed period, with no occasion-specific shift. Occasion 1 is sampled at 1 and 3 hours, while occasion 2 is sampled at 5 and 7 hours. The observed residuals are \(0.1, 0.3\) on occasion 1 and \(0.5, 0.7\) on occasion 2.

The raw occasion means and contrast are

$$ \bar r_{i1}=\frac{0.1+0.3}{2}=0.2,\qquad \bar r_{i2}=\frac{0.5+0.7}{2}=0.6,\qquad \bar r_{i2}-\bar r_{i1}=0.4. $$

It would be misleading to call \(0.4\) an occasion shift without considering time. The mean sampling times are 2 and 6 hours, a difference of 4 hours. The stated time trend predicts a difference of \(0.10(6-2)=0.4\) residual units from time alone. In the decomposition, \(c_{i2}-c_{i1}=0\), while the difference in average \(g(t)\) is \(0.4\). The data are exactly consistent with the stipulated time trend and no occasion-specific component. A useful next step is to compare occasions where their time ranges overlap or examine residuals against time within each occasion.

Worked Example: Separating Stable Subject Misfit From Occasion Patterns

Consider two hypothetical subjects with occasion-mean residuals as follows: subject A has \(0.7\) and \(0.8\); subject B has \(-0.6\) and \(-0.5\), for occasions 1 and 2. Suppose their sampling times are comparable across occasions. The grand occasion means are

$$ \bar r_{\cdot 1}=\frac{0.7+(-0.6)}{2}=0.05,\qquad \bar r_{\cdot 2}=\frac{0.8+(-0.5)}{2}=0.15. $$

The pooled means differ by only \(0.15-0.05=0.10\), which might look small. But the paired contrasts are \(0.8-0.7=0.1\) for A and \(-0.5-(-0.6)=0.1\) for B, so both subjects show the same modest occasion contrast. Separately, A's residuals are high on both occasions and B's are low on both. That pattern suggests stable subject-level residual tendencies in this display, not an occasion-2 shift large enough to explain the between-subject separation.

This example shows why both the paired differences and the occasion levels matter. A pooled comparison can be dominated by which subjects contribute data, while a paired comparison removes stable subject-level differences only under its common-component interpretation. It does not remove unequal time support or occasion-specific changes in other conditions.

Diagnostics, Alternatives, and Limitations

A practical review proceeds from the display to the comparability of the data, then to possible explanations. Inspect raw residual points as well as subject-level summaries; a mean can hide a few large residuals or a time-ordered pattern. For each subject, ask whether an occasion difference persists at comparable times and whether it appears in more than a few subjects. Check that the same residual definition and scale are used throughout. When individual prediction overlays are available, look for systematic under- or overprediction on one occasion rather than relying only on a single numerical summary.

  • Time trend: residuals may vary with time, and occasions with different time distributions can have different means even without an occasion-specific shift.
  • Unequal sampling: a mean from many observations can dominate a pooled summary, while a sparsely sampled occasion may be unstable. Show counts and consider subject-level paired summaries.
  • Changing conditions: dose, regimen, assay, study procedures, or other recorded factors may differ across occasions. A visual association with occasion does not distinguish these explanations.
  • Residual dependence and noise: multiple observations from one subject are not automatically independent. A cluster of residuals is not equivalent to the same number of independent subjects.
  • Model and data issues: an apparent shift can reflect prediction errors, recording or timing problems, or a mismatch in the residual scale, not only structural-model misspecification.

Within-subject plots are complementary to residuals pooled by study, site, or assay and to residuals plotted against time. Grouped plots can reveal differences between groups but may mix those differences with subject composition. Time plots can show a common trend but may obscure whether it occurs consistently within subjects. Occasion diagnostics focus on repeated periods within subjects; they do not replace either comparison. Formal models for repeated observations can quantify uncertainty under explicit assumptions, but choosing and interpreting such models requires more than visual inspection.

The main limitation is incomplete overlap. If occasion 1 contains only early times and occasion 2 only late times, the data may not separate an occasion contrast from a time trend without additional assumptions. Likewise, if only a few subjects have observations on both occasions, paired patterns may not represent the full sample. State these limitations rather than treating a plot as a causal or definitive test.

Common pitfall: “The mean residual is higher on occasion 2, so the model has an occasion effect.” This ignores subject composition and the fact that occasion means may average different times, doses, or other conditions. Instead, examine within-subject contrasts, check time overlap and residual comparability, and describe the result as a diagnostic pattern requiring follow-up—not as proof of its cause.

Check Your Understanding

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

  1. Subject D has occasion-1 mean residual \(0.4\) and occasion-2 mean residual \(-0.2\). What is the paired contrast, defined as occasion 2 minus occasion 1, and what does its sign indicate?
  2. Why does subtracting two occasion means not necessarily leave only the difference in occasion-associated components?
  3. Across several subjects, occasion 2 has a larger pooled mean residual. Name two checks needed before interpreting this as a within-subject occasion pattern.
  4. In the schematic decomposition, both occasions for a subject have the same \(a_i\), but their average time contributions differ by \(0.3\) and their occasion components are equal. If their average remaining variations are equal, what is the expected mean contrast from those terms?

Solutions. (1) The contrast is \(-0.2-0.4=-0.6\) standardized-residual units. It indicates a lower mean residual on occasion 2 for this subject; it does not by itself establish why. (2) The time contributions and remaining-variation averages can also differ, so the full contrast includes those differences as well as the occasion-component difference. (3) Check paired subject-level contrasts and compare sampling-time support; also verify a common residual definition and examine whether the same subjects contribute to both occasions. (4) The stable component cancels, the occasion-component difference is zero, and the remaining-variation difference is zero. The contrast is therefore \(0.3\) standardized-residual units from the time contribution alone.