Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Residual Diagnostics Across Clinical Subgroups

Model Diagnostics · Tutorial 617 of 697

Residual Diagnostics Across Clinical Subgroups

Learn to stratify longitudinal and survival residual displays responsibly, interpret subgroup patterns, and distinguish diagnostic signals from noise or artifacts.

Advanced 11 min read

What You'll Learn

  • Define subgroup-specific longitudinal and survival residual summaries.
  • Explain how opposing subgroup residual patterns can cancel in pooled displays.
  • Work through subgroup means, martingale residual sums, and time-binned residuals.
  • Check assumptions about subgroup definition, censoring, and residual scaling.
  • Compare stratified displays with pooled displays and subgroup-specific refitting.
  • Recognize sparse-data, multiplicity, and estimation pitfalls.

Why inspect residuals by clinical subgroup?

A residual display can look acceptable overall while revealing systematic errors within clinically important groups. For example, a joint model may overpredict biomarker values in one subgroup and underpredict them in another. When the groups are pooled, the errors can cancel. A pooled event-residual display can mask the same problem if one group experiences more events than its fitted model expects while another experiences fewer.

Subgroup stratification means displaying or summarizing residuals separately for clinically relevant groups, then comparing their patterns. It is a diagnostic view of the fitted model, not a new model and not, by itself, a formal test. The aim is to find patterns that suggest a missing group effect, a group-specific trajectory or hazard shape, or another mismatch that deserves investigation.

Let \(G_i\) denote the clinical group for subject \(i\), such as a baseline disease category. Let \(Y_{ij}\) be the longitudinal measurement for subject \(i\) at time \(t_{ij}\), and let \(N_i(t)\) count that subject’s observed events by time \(t\). A longitudinal residual compares an observed measurement with its fitted value. A survival martingale residual compares the observed event count with the event count expected under the fitted intensity. In practice, use residual definitions and censoring conventions appropriate to the diagnostic being examined; the earlier material on residual diagnostics under right censoring is relevant when observations are censored.

Definition: A subgroup-stratified residual display separates residuals or residual summaries by a clinically defined group \(G_i\). For longitudinal data, it may show residuals against time or fitted values within each group. For survival data, it may show group-specific martingale-residual summaries or cumulative residual patterns over time. The display asks whether the residual behaviour is similar to what the fitted model implies within each group—not merely whether residuals average near zero after pooling.

Conditions for a useful comparison

The subgroup should be defined in a way that makes the comparison interpretable. A baseline clinical category is usually straightforward: membership is determined before the outcomes being diagnosed. If group membership changes over time, the display must respect when a subject belongs to each group; assigning the entire history to a group defined using future information can create misleading patterns.

Residual construction and scaling also matter. A raw longitudinal residual \(Y_{ij}-\widehat{m}_i(t_{ij})\) is in the biomarker’s measurement units. A standardized residual divides by an appropriate estimated standard deviation, but the denominator must match the intended comparison. For example, a residual standardized using only measurement error is not equivalent to one standardized using the full predictive variability. If residuals account for estimated subject-specific random effects, they can appear less variable than residuals that account for uncertainty in those effects. Compare like with like across groups.

For survival diagnostics, the martingale residual for subject \(i\) at the end of follow-up can be written as

$$ M_i(\tau)=N_i(\tau)-\int_0^\tau Y_i(u)\widehat{\lambda}_i(u)\,du, $$

where \(Y_i(u)\) indicates that subject \(i\) is still under observation and at risk just before time \(u\), and \(\widehat{\lambda}_i(u)\) is the fitted event intensity on the scale required by the model. Under the correctly specified intensity and censoring conditions, the martingale residual has mean zero in the relevant risk-process formulation. The compensator integral accounts for the subject’s observed time at risk; simply comparing event counts without accounting for follow-up is generally not an adequate survival diagnostic.

These properties do not turn a subgroup display into a calibrated test. Repeated observations within a subject are dependent, survival residuals are shaped by risk sets and censoring, and small subgroups can produce unstable patterns. A residual mean close to zero is not proof of fit; it is one feature to inspect alongside time patterns, spread, and the event-process diagnostics appropriate to the data.

How pooling hides subgroup patterns

The basic cancellation mechanism is an ordinary weighted average. If subgroup \(g\) contains \(n_g\) residuals with mean \(\bar r_g\), the pooled residual mean is

$$ \bar r_{\text{pooled}}=\frac{\sum_g n_g\bar r_g}{\sum_g n_g}. $$

Opposing subgroup means can therefore yield a pooled mean near zero. The same logic applies to time-specific summaries and to sums of survival residuals. The pooled display answers whether errors remain on average across the entire sample; it does not answer whether errors remain within each clinical group.

A useful workflow is to keep the diagnostic scale and axes consistent, show the number of subjects or observations contributing to each subgroup, and compare both group-specific and pooled displays. For longitudinal residuals, inspect residuals against time and fitted values within each group. For survival residuals, examine group-specific residual patterns over follow-up while respecting censoring and the risk set. A group difference in residual behaviour is evidence to investigate, not automatic evidence that a particular model extension is needed.

Worked Example: Opposing Longitudinal Residual Means

Suppose a hypothetical clinical analysis has two baseline groups, A and B, with eight subjects in each. For simplicity, assume one standardized longitudinal residual summary per subject has been calculated using the same residual definition and scale in both groups. Group A’s mean residual is \(0.60\); group B’s is \(-0.60\). Positive residuals mean observed biomarker values tend to exceed fitted values.

The pooled mean is

$$ \bar r_{\text{pooled}} =\frac{8(0.60)+8(-0.60)}{16} =\frac{4.80-4.80}{16} =0. $$

The pooled mean suggests no average signed error, but the subgroup summaries point in opposite directions: the fitted values tend to be too low in A and too high in B. The calculation establishes cancellation, not statistical significance. We would inspect the residuals against time and fitted values within each group, check whether the pattern is driven by a few subjects, and consider whether the clinical grouping or model structure plausibly explains the contrast.

Survival residuals need the risk-set context

For a survival display, compare observed events with fitted cumulative expected events within each group. If \(G_i=g\) is a baseline group, the group’s terminal martingale-residual sum is the observed event total minus the sum of individual fitted compensators. It is a signed diagnostic summary. Its raw magnitude depends on group size and follow-up, so comparing unscaled sums across groups of different sizes can be misleading. The time course of the residuals can also matter: a final sum near zero may conceal early positive and later negative departures.

Worked Example: Event Residuals That Cancel Across Groups

Consider hypothetical groups A and B, each with 40 subjects. After accounting for each subject’s time at risk and the fitted joint-model event intensity, the sums of fitted cumulative expected event counts are 12 in A and 12 in B. The observed event counts are 18 in A and 6 in B.

For each group, the sum of terminal martingale residuals is observed events minus fitted expected events:

$$ \sum_{i:G_i=A}M_i=18-12=6,\qquad \sum_{i:G_i=B}M_i=6-12=-6. $$

Across both groups, the residual sum is \(6+(-6)=0\). Dividing by the 40 subjects in each group gives descriptive averages of \(6/40=0.15\) and \(-6/40=-0.15\) residual events per subject. These are not rates per unit time and are not p-values. They show that the pooled signed total hides opposite group departures. Before interpreting them, check the group-specific risk-set histories, censoring, and residual-versus-time displays; the same terminal sums can arise from very different time patterns.

Time patterns can differ even when group totals do not

Stratifying only by a group-wide mean can miss a trajectory problem. The fitted longitudinal trend may be wrong in opposite directions at different times, or the error may differ between groups. Binning time can make broad patterns visible, but bin boundaries should be chosen for clinical or measurement reasons where possible. Bins with few observations should be shown as uncertain rather than treated as precise summaries. A smooth curve can be helpful, but its apparent smoothness does not remove sampling variability or within-subject dependence.

Worked Example: Opposite Group-by-Time Patterns

Suppose a hypothetical data set has five observations contributing to each group-by-period cell. The means of standardized longitudinal residuals are as follows:

Clinical groupEarly period meanLate period mean
A-0.500.50
B0.50-0.50

With five observations in each cell, the four cell residual sums are \(5(-0.50)=-2.50\), \(5(0.50)=2.50\), \(5(0.50)=2.50\), and \(5(-0.50)=-2.50\). Their total is

$$ -2.50+2.50+2.50-2.50=0. $$

Thus, the pooled signed residual mean is zero, and each group’s mean across the two equally sized periods is also zero. Yet the time pattern reverses by group: residuals tend to move from negative to positive in A and from positive to negative in B. A plot of each group against time could reveal a group-specific trajectory mismatch that a pooled mean conceals. This small example does not establish that such a pattern is real; it motivates checking individual trajectories, observation counts, and the fitted model’s uncertainty.

Interpreting a subgroup display and choosing next steps

A visible subgroup pattern has several possible explanations. The mean structure may omit a group effect or group-by-time relationship; the event component may not represent group-specific hazard behaviour; a few influential subjects may dominate; or the residual scale may differ for legitimate reasons. Clinical groups can also differ in measurement schedules, follow-up, or censoring. Those features must be considered before attributing a residual pattern to model misspecification.

The main alternatives answer different questions. A pooled display is simpler and can be more stable, but it can conceal opposing patterns. A stratified display retains the fitted model while asking whether its errors differ by group. Refitting separate subgroup models can reveal different fitted structures, but it uses less data per fit and may make parameters difficult to compare. Adding group terms or interactions to one model directly represents a proposed difference, but should follow a defensible diagnostic and clinical rationale. A subgroup display is therefore a way to locate and describe potential misfit, not a substitute for model comparison or a claim of causal effect.

There are practical limitations. Looking at many groups, time windows, and residual types increases the chance of noticing chance irregularities. Very small groups make averages and curves unstable. Data-driven cut points can exaggerate apparent contrasts, and groups defined after observing outcomes can lead to biased interpretation. Report which groups and summaries were examined, include denominators, and treat exploratory patterns as hypotheses for further assessment. Do not infer that a model is adequate merely because each subgroup mean is near zero: residual spread, shape, time dependence, and survival calibration may still be wrong.

Common pitfalls

  • Relying only on the pooled average. Opposing subgroup errors can cancel. Inspect group-specific patterns as well as the pooled display.
  • Comparing raw survival residual sums across unequal groups. Sums depend on group size and exposure. Show group sizes and risk-set context, and use an appropriate scale for comparisons.
  • Treating a pattern as a test result. A residual plot does not provide a p-value or prove misspecification. Account for variability and dependence before making inferential claims.
  • Using inconsistent residual scales. Apparent group differences can be artifacts if residuals are standardized differently or use different uncertainty components.
  • Ignoring observation and censoring patterns. Sparse visits or unequal follow-up can make subgroup residual curves incomparable without careful context.
Key takeaway: Stratification can expose clinically specific residual patterns that disappear after pooling. Interpret such patterns as diagnostic evidence to investigate, checking residual construction, time and risk-set structure, group size, and uncertainty before changing the model.

Check Your Understanding

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

  1. Two equally sized groups have mean longitudinal residuals of \(0.40\) and \(-0.40\). What is the pooled mean, and what does it fail to show?
  2. Why is a group’s observed event count alone not enough to diagnose survival-model fit when follow-up differs?
  3. In the time-pattern example, why can both group-wide means and the pooled mean be zero while a useful diagnostic pattern remains?
  4. Name two reasons a subgroup residual contrast might be misleading even if it is visually clear.
  5. How does a stratified display differ from fitting separate models in every subgroup?

Solutions. 1. The pooled mean is \((0.40-0.40)/2=0\); it fails to show the opposing directions of error within the two groups. 2. Subjects contribute different amounts of time at risk, so observed events must be considered relative to fitted expected events based on the risk process and censoring. 3. Early and late residual means cancel within each group, while the directions of change differ between groups; plotting by group and time preserves that structure. 4. Examples include small subgroup size, influential subjects, different observation schedules, censoring differences, inconsistent scaling, or chance patterns among many comparisons. 5. A stratified display examines residuals from the same fitted model separately by group; separate fits estimate distinct models using less data per fit and may yield less directly comparable parameters.

Clinical Biostats