Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Diagnosing Heteroscedasticity In Longitudinal Residuals

Model Diagnostics · Tutorial 599 of 697

Diagnosing Heteroscedasticity In Longitudinal Residuals

Use plots and stratified summaries to distinguish changing residual spread from trajectory misspecification or dependence, and decide what to check next.

Advanced 10 min read

What You'll Learn

  • Define heteroscedasticity in the longitudinal residual distribution.
  • Construct and interpret a scale-location plot.
  • Compare residual variances across fitted-value, time, and predicted-risk strata.
  • Recognize how repeated measures and estimated random effects affect these diagnostics.
  • Distinguish descriptive variance checks from formal tests and model changes.

Why Check Residual Spread?

A longitudinal model can describe the average marker trajectory well while still getting the scatter around that trajectory wrong. For example, measurement error may increase as a marker rises, or residual variation may be greater late in follow-up than early in follow-up. Such changes in spread are called heteroscedasticity. They matter because a model that assumes one residual variance may give misleading standard errors, prediction intervals, and measures of uncertainty, even when its fitted mean looks plausible.

Here the focus is the longitudinal component of a joint model. A residual is the observed marker value minus its fitted value. For a Gaussian longitudinal submodel, a useful starting point is the conditional residual for subject \(i\) at visit \(j\), calculated using that subject’s estimated random effects. The residual’s sign describes whether the observation is above or below its fitted value; its magnitude describes the discrepancy. Earlier material on residual types distinguishes conditional residuals from marginal residuals. For this variance check, use one residual definition consistently and state which fitted values and residuals produced the diagnostic.

Definition: Longitudinal residuals are heteroscedastic when their conditional variance is not constant across observations. A model with constant residual variance assumes, for example, that \(\operatorname{Var}(\epsilon_{ij}\mid b_i,t_{ij},x_{ij})=\sigma^2\), where \(b_i\) denotes the subject-specific random effects and \(x_{ij}\) represents relevant covariates. A heteroscedastic alternative allows this variance to depend on quantities such as fitted marker value, follow-up time, or a risk group.

This assumption concerns residual spread, not the spread of the observed marker values themselves. Observations can vary more at later visits simply because the mean trajectory changes over time. The diagnostic question is whether the residuals, after accounting for the fitted mean and the chosen random-effects structure, also show changing spread.

Scale-Location Plots and Stratified Summaries

A scale-location plot places a measure of residual magnitude on the vertical axis and a potential driver of variance on the horizontal axis. A common choice is the square root of the absolute standardized residual, \(\sqrt{|r_{ij}|}\), plotted against the fitted marker value. The standardization should use a clearly stated reference scale, such as a common residual standard deviation estimate. A horizontal cloud with roughly similar vertical spread is compatible with constant variance. A smooth upward or downward trend, or a changing vertical spread, suggests that residual scale may vary with fitted value.

The square root transformation makes large absolute residuals less dominant than they would be on a plot of squared residuals. The plot is a visual diagnostic, not a test with a universal rejection threshold. It should be supplemented by plots against follow-up time and other prespecified variables that could plausibly be associated with residual scale.

$$ \text{If } \epsilon_{ij}=\sigma(x_{ij})Z_{ij}, \quad Z_{ij}\sim N(0,1), \qquad E\!\left[\sqrt{|\epsilon_{ij}|}\mid x_{ij}\right] =\sqrt{\sigma(x_{ij})}\,E\!\left[\sqrt{|Z_{ij}|}\right]. $$

This relation gives a simple justification for the scale-location plot: if the residual standard deviation \(\sigma(x_{ij})\) changes with \(x_{ij}\), the expected square-root absolute residual changes too. If \(\sigma(x_{ij})\) is constant, the expected value is constant, although random fluctuation can still make a finite plot look uneven.

A complementary check divides observations into a few meaningful strata, such as early versus late follow-up, lower versus higher fitted values, or low versus high predicted event risk. Within each stratum, calculate the sample variance of the residuals:

$$ s_g^2=\frac{\sum_{k=1}^{n_g}(e_{kg}-\bar e_g)^2}{n_g-1}, \qquad \bar e_g=\frac{1}{n_g}\sum_{k=1}^{n_g}e_{kg}. $$

Here \(e_{kg}\) is the residual for observation \(k\) in stratum \(g\), and \(n_g\) is the number of observations in that stratum. Report the group sizes as well as the variances: a variance based on very few observations is unstable. These summaries are descriptive unless their sampling uncertainty is calculated with a method that respects the repeated-measures structure.

Worked Example: Comparing Early and Late Residual Spread

Suppose a hypothetical Gaussian longitudinal fit gives three conditional residuals in an early-follow-up stratum, measured in marker units: \(-1,0,1\). In a late-follow-up stratum, the residuals are \(-2,0,2\). Assume for this illustration that the mean residual is zero in each stratum, as verified by the displayed values.

For early follow-up, \(n_{\mathrm{early}}=3\), and \(s_{\mathrm{early}}^2=[(-1)^2+0^2+1^2]/(3-1)=2/2=1\) marker-units squared.

For late follow-up, \(n_{\mathrm{late}}=3\), and \(s_{\mathrm{late}}^2=[(-2)^2+0^2+2^2]/(3-1)=8/2=4\) marker-units squared. The late-to-early variance ratio, calculated from the unrounded variances, is \(4/1=4.000\). In this small hypothetical sample, residual variance is four times as large late as early. This is a descriptive signal to investigate, not by itself evidence that follow-up time causes the larger spread.

Checking Fitted Values and Risk Groups

Variance may change across the range of fitted marker values even when it does not change monotonically over time. A scale-location plot against fitted values can reveal a fan shape: residual magnitudes become larger as fitted values increase. Stratified variances can make that pattern easier to summarize, but the strata should be selected to make comparisons interpretable rather than chosen after searching for the largest contrast.

Worked Example: Residual Variance Across Fitted Values

In a hypothetical analysis, two observations with lower fitted values have residuals \(-1\) and \(1\) marker units. Three observations with higher fitted values have residuals \(-2,0,2\). The displayed residuals sum to zero in each group, so the group means are both zero.

For the lower-fitted-value group, \(s_{\mathrm{low}}^2=[1+1]/(2-1)=2\) marker-units squared. For the higher-fitted-value group, \(s_{\mathrm{high}}^2=[4+0+4]/(3-1)=8/2=4\) marker-units squared. The variance ratio is \(4/2=2.000\): the observed residual variance in the higher fitted-value group is twice that in the lower group. Because there are only two and three observations, respectively, the ratio is highly uncertain; the corresponding scale-location plot and a larger sample should be examined before changing the model.

Risk-group checks need extra care. A group may be defined by predicted event risk, but residual variance in the marker process is not itself an event-risk measure. A difference between risk strata can flag a subgroup whose marker model fits with different precision, but it does not establish a biological mechanism. If a subject contributes multiple visits, visits from that subject are not independent observations. Do not treat all such visits as independent replicates when quantifying uncertainty.

Worked Example: Comparing Residual Spread by Predicted Risk

Suppose a hypothetical analysis uses one prespecified visit per subject, avoiding multiple residuals from the same subject in this summary. Residuals for three subjects in a lower predicted-risk group are \(-1,0,1\) marker units. Residuals for five subjects in a higher predicted-risk group are \(-2,-1,0,1,2\). Both group means equal zero.

The lower-risk variance is \(s_{\mathrm{low}}^2=(1+0+1)/(3-1)=1\) marker-units squared. The higher-risk variance is \(s_{\mathrm{high}}^2=(4+1+0+1+4)/(5-1)=10/4=2.5\) marker-units squared. The variance ratio, using the exact values, is \(2.5/1=2.500\). The residual spread is larger in the higher-risk group in this example, but the small group sizes make this a prompt for follow-up rather than a definitive subgroup conclusion.

Assumptions, Interpretation, and Follow-Up

A variance diagnostic is meaningful only relative to a fitted mean and a residual definition. The longitudinal mean trajectory should be adequately specified; otherwise, a systematic mean error can create large residuals in one region and mimic changing variance. The random-effects structure and any modeled within-subject dependence should also be plausible. Residual autocorrelation can make nearby residuals move together, affecting the apparent pattern and the uncertainty of variance summaries. A plot can reveal such concerns, but a variance comparison does not repair them.

For each diagnostic, check that the comparison is not driven by a few extreme observations, a very small stratum, or a change in visit composition. Consider plotting residuals against time and fitted values separately, checking whether group means remain near zero, and displaying group counts. If using conditional residuals, remember that the subject-specific random effects are estimated rather than known. Their estimation can shrink residuals and induce dependencies; the resulting residuals are not a collection of independent, identically distributed errors.

When evidence of heteroscedasticity is persistent and scientifically plausible, a model can allow the residual variance to depend on a covariate. For instance, one may model the log residual variance as a linear function of follow-up time, which ensures a positive variance after exponentiation. Any revised model should be refitted and its residual patterns rechecked; changing the variance structure cannot compensate for an incorrect mean trajectory. The specific variance function should be parsimonious and supported by the design and subject-matter context.

A formal variance test can be an alternative to visual and descriptive checks, but familiar tests based on independent normal observations do not automatically apply to repeated longitudinal residuals. For example, treating every visit as an independent observation can yield an incorrect standard error or p-value. If inferential uncertainty is needed, use an approach that accounts for clustering by subject, such as resampling subjects and repeating the relevant fitting and summary steps. Even then, the test addresses a specified contrast or variance model, not every possible form of changing spread.

ApproachWhat it helps revealMain caution
Scale-location plotGradual trends and fan-shaped changes in residual magnitudeVisual patterns can be noisy and depend on the chosen residual standardization
Variance-stratified summariesMagnitude of spread differences in interpretable groupsSmall groups and repeated visits can make comparisons unstable or dependent
Formal variance testEvidence for a prespecified variance contrast under its assumptionsTests assuming independent observations may be invalid for longitudinal data
Variance-function modelA structured way to represent changing residual scaleRequires a defensible functional form and can be confounded with mean misspecification

Common Pitfalls and Limitations

  • Confusing a changing mean with changing variance. A rising marker trajectory is not evidence of heteroscedasticity if residual spread is constant around that trajectory. Examine residuals, not raw marker values alone.
  • Calling a visual pattern a test result. A funnel shape is a diagnostic signal, not a p-value or proof that a variance assumption is false.
  • Ignoring dependence. Repeated residuals from one subject do not supply the same independent information as residuals from different subjects. Summaries remain useful descriptively, but standard errors and tests need to respect clustering.
  • Overinterpreting strata. Risk groups or time bins chosen after inspecting many alternatives can exaggerate apparent differences. Prefer prespecified, interpretable comparisons and report their sizes.

These checks have limits. Conditional residuals depend on estimated random effects, and the apparent spread may reflect mean misspecification, an inadequate dependence structure, or influential observations rather than a variance mechanism alone. A lack of a visible trend is not proof of constant variance, particularly with sparse follow-up or small samples. Use the plots and summaries as part of a diagnostic argument, then revisit model assumptions and the scientific context.

Key takeaway: Diagnose longitudinal heteroscedasticity by checking residual magnitude against fitted value, follow-up time, and relevant groups, then compare interpretable stratum variances. Treat these as dependent-data diagnostics, not automatic independent-sample tests.

Check Your Understanding

Answer each question, then compare with the brief solutions.

  1. What pattern in a scale-location plot would be consistent with residual standard deviation increasing as fitted marker values increase?
  2. Why is a variance ratio based on visits from the same subjects not automatically an independent-sample comparison?
  3. For residuals \(-1,0,1\) in one group and \(-2,0,2\) in another, calculate both sample variances and their ratio.
  4. Why should a residual plot against time be interpreted alongside a check of the fitted mean trajectory?

Solutions. (1) The square-root absolute standardized residuals tend to rise with fitted value, often appearing as a widening or upward pattern. (2) Within-subject residuals can be dependent, so treating visits as independent can misstate uncertainty. (3) The variances are \(2/2=1\) and \(8/2=4\) marker-units squared; the second-to-first ratio is \(4.000\). (4) An incorrect mean trajectory can create systematic residual magnitudes over time and imitate changing residual variance.

Clinical Biostats