Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Residual Error Versus Random-Effects Variation

Mixed Models Review · Tutorial 71 of 697

Residual Error Versus Random-Effects Variation

Learn to identify subject-level random-effects variation and occasion-level residual error, quantify their contributions at a given visit, and recognize when the distinction is obscured.

Intermediate 10 min read

What You'll Learn

  • Distinguish a subject’s shared random effects from visit-specific residual error.
  • Write the longitudinal model that separates the mean trajectory, random effects, and residuals.
  • Calculate the contributions of random intercepts, random slopes, and residual variance at a given time.
  • Explain how assumptions about residual errors affect the interpretation of variation.
  • Recognize why raw biomarker variability alone cannot identify its source.
  • Identify diagnostics and model limitations relevant to separating the two sources.

Why Separate the Sources of Variation?

Two biomarker measurements can differ because the subjects have genuinely different underlying trajectories, because each measurement has occasion-level error, or because both sources contribute. These explanations matter: variation that persists across visits for the same subject is not the same as variation that changes from one occasion to the next. A model that treats all observed spread as one undifferentiated quantity can therefore misrepresent individual differences or measurement noise.

The distinction is central to longitudinal analysis. A subject’s random intercept represents a departure from the population trajectory that is shared across that subject’s visits. A random slope represents a subject-specific departure in the rate of change. A residual is the remaining occasion-specific deviation after accounting for the mean trajectory and the subject’s random effects. The earlier material on fixed-effects mean trajectories and random intercepts and slopes supplies these model components; here the focus is how their variation differs.

A Model With Two Sources of Variation

Let \(y_{ij}\) be the biomarker measurement for subject \(i\) at visit \(j\), at time \(t_{ij}\). A linear mixed model can be written as

$$ y_{ij}=x_{ij}^{\mathsf T}\beta+z_{ij}^{\mathsf T}b_i+\varepsilon_{ij}. $$

Here \(x_{ij}^{\mathsf T}\beta\) is the population mean at that subject’s visit, \(b_i\) is the vector of subject-specific random effects, \(z_{ij}\) describes how those effects enter the measurement, and \(\varepsilon_{ij}\) is the occasion-level residual. In a random-intercept-and-slope model, \(b_i=(b_{0i},b_{1i})^{\mathsf T}\) and \(z_{ij}=(1,t_{ij})^{\mathsf T}\). The subject’s random contribution at time \(t_{ij}\) is then \(b_{0i}+t_{ij}b_{1i}\).

Definition: Random-effects variation is the between-subject variation in the latent departures represented by \(b_i\). Residual variation is the occasion-level variation represented by \(\varepsilon_{ij}\), after accounting for the population mean and the subject’s random effects. These are distinct model components, not two names for the same unexplained spread.

For the basic variance calculation below, assume \(E(b_i)=0\), \(\operatorname{Var}(b_i)=D\), \(E(\varepsilon_{ij})=0\), and \(\operatorname{Var}(\varepsilon_{ij})=\sigma^2\). Also assume that the random effects are independent of the residuals. For the simplest residual specification, residuals from different occasions are independent. These assumptions describe a standard starting model, not a requirement that every longitudinal data set must satisfy.

The population mean \(x_{ij}^{\mathsf T}\beta\) describes systematic change, not random variation. The random effect \(z_{ij}^{\mathsf T}b_i\) is shared through the subject and may change with time through \(z_{ij}\). The residual \(\varepsilon_{ij}\) is indexed by the particular occasion. A residual can be positive or negative, and a subject’s residual need not have the same sign at successive visits.

How the Components Contribute at One Visit

At a specified visit, the deviation from the population mean is \(z_{ij}^{\mathsf T}b_i+\varepsilon_{ij}\). Under the assumptions just stated, its variance is

$$ \begin{aligned} \operatorname{Var}(y_{ij}\mid x_{ij},z_{ij}) &=\operatorname{Var}(z_{ij}^{\mathsf T}b_i+\varepsilon_{ij})\\ &=\operatorname{Var}(z_{ij}^{\mathsf T}b_i) +\operatorname{Var}(\varepsilon_{ij}) +2\operatorname{Cov}(z_{ij}^{\mathsf T}b_i,\varepsilon_{ij})\\ &=z_{ij}^{\mathsf T}Dz_{ij}+\sigma^2. \end{aligned} $$

The final equality uses independence, which makes the covariance term zero, and \(\operatorname{Var}(z_{ij}^{\mathsf T}b_i)=z_{ij}^{\mathsf T}Dz_{ij}\). This is a single-visit variance calculation: one contribution comes from differences in subject effects at that time, and the other from residual error. It does not imply that the random-effects contribution is constant over time. Nor does it by itself describe how two visits from the same subject co-vary.

With a random intercept and slope, write

$$ D= \begin{pmatrix} \tau_{00}&\tau_{01}\\ \tau_{01}&\tau_{11} \end{pmatrix}. $$

Then the random-effects contribution at time \(t\) is \(\tau_{00}+2t\tau_{01}+t^2\tau_{11}\). Thus, the amount of between-subject variation in the latent trajectory can depend on the time origin and the visit time. By contrast, in this basic model the residual contribution is \(\sigma^2\) at every occasion. If the residual variance is not constant, this last assumption must be changed rather than silently imposed.

Worked Example: Separating Two Variance Contributions

Suppose a hypothetical biomarker is modeled with a random intercept whose variance is \(9\) \((\text{mg/L})^2\), and independent residual errors with variance \(16\) \((\text{mg/L})^2\). There is no random slope. Calculate the two contributions to variability at a visit and the total variance under the model.

For a random-intercept model, \(z_{ij}=1\), so the random-effects contribution is \(1(9)(1)=9\) \((\text{mg/L})^2\). The residual contribution is \(\sigma^2=16\) \((\text{mg/L})^2\). Independence gives

$$ \operatorname{Var}(y_{ij})=9+16=25\;(\text{mg/L})^2. $$

The model therefore attributes \(9/25=0.36\), or 36%, of the single-visit variance to differences in subject baselines, and \(16/25=0.64\), or 64%, to occasion-level residual error. The total standard deviation at a visit is \(\sqrt{25}=5\) mg/L. These are model-based proportions under the stated assumptions; they are not proportions that can be read directly from one observed measurement.

Worked Example: A Random Slope Changes the Contribution Over Time

Consider a hypothetical biomarker model with time measured in years from baseline. Let the random-intercept variance be \(4\) \((\text{mg/L})^2\), the random-slope variance be \(0.25\) \((\text{mg/L/year})^2\), and their covariance be \(-0.5\) \((\text{mg/L})^2/\text{year}\). Let the residual variance be \(1.5\) \((\text{mg/L})^2\), constant over time. Find the random-effects contribution and total variance at baseline and at year 2.

At time \(t\), the random-effects contribution is \(4+2t(-0.5)+t^2(0.25)\). At baseline, \(t=0\), so this is

$$ 4+2(0)(-0.5)+(0)^2(0.25)=4\;(\text{mg/L})^2. $$

Adding the residual variance gives a total variance of \(4+1.5=5.5\;(\text{mg/L})^2\) at baseline. At year 2, the random-effects contribution is

$$ 4+2(2)(-0.5)+(2)^2(0.25)=4-2+1=3\;(\text{mg/L})^2. $$

The total variance at year 2 is \(3+1.5=4.5\;(\text{mg/L})^2\). The calculation uses the specified covariance as well as both variances. The negative covariance makes the random-intercept and random-slope contributions partly offset at this time; it does not mean either variance is negative. This example also shows why one should not describe random-effects variation as a single time-invariant amount when slopes are random.

Reading the Distinction in Observed Measurements

The model’s components are latent quantities; an observed value does not arrive labeled with its source of deviation. Consider a small hypothetical data set with population means of 100 mg/L at visit 1 and 102 mg/L at visit 2. Suppose subject A has a random intercept of \(+2\) mg/L and subject B has a random intercept of \(-1\) mg/L. Suppose A’s residuals are \(+1\) and \(-1\) mg/L, while B’s residuals are 0 and 0 mg/L.

Worked Example: Identifying Subject and Occasion Deviations

Use \(y_{ij}=\mu_j+b_i+\varepsilon_{ij}\) to calculate the four hypothetical measurements and identify their components.

For subject A at visit 1, \(100+2+1=103\) mg/L. At visit 2, \(102+2-1=103\) mg/L. For subject B at visit 1, \(100-1+0=99\) mg/L; at visit 2, \(102-1+0=101\) mg/L. A’s \(+2\) and B’s \(-1\) are each carried across visits because they are subject random intercepts. A’s \(+1\) and \(-1\) differ by occasion and are residuals. The example illustrates the model’s bookkeeping; these four observations are not enough to estimate reliable variance components.

The population mean changes by \(2\) mg/L between visits. After subtracting those visit-specific means, A’s deviations are \(3\) and \(1\) mg/L, while B’s are \(-1\) and \(-1\) mg/L. For A, the change in the centered deviation is \(1-3=-2\) mg/L, exactly the change in residuals, because the random intercept is unchanged. This is a useful conceptual check: a shared random intercept does not create a within-subject change over time.

Assumptions, Diagnostics, and Alternatives

The variance calculation is only as useful as its assumptions. In the basic model, random effects have mean zero and a common covariance matrix \(D\); residuals have mean zero and variance \(\sigma^2\); and random effects and residuals are independent. The simple version also assumes residual independence across occasions. In applying the model, the time scale and units must be coherent, the chosen fixed mean should describe systematic trajectory patterns adequately, and the random-effects structure should be plausible for the subjects and visits observed.

Diagnostics can indicate when the distinction is being modeled poorly, although they do not prove the assumptions. Useful checks include:

  • Plot residuals against fitted values and time. A systematic pattern can indicate a misspecified mean trajectory; a widening or narrowing residual spread can signal that a constant \(\sigma^2\) is unsuitable.
  • Compare residuals from the same subject across visits. Patterns of persistent same-subject residuals may be inconsistent with the assumed residual independence.
  • Inspect subject-specific deviations and fitted trajectories for extreme or implausible patterns. A few unusual subjects can strongly influence estimates of random-effects variation.
  • Check that the random-intercept-and-slope specification is supported by the follow-up schedule. If many subjects have few or narrowly timed observations, their individual slopes may be weakly informed.

These checks distinguish possible sources of model misfit, but they cannot establish that an observed deviation is “really” a random effect rather than residual error. The allocation depends on the model and its data. Limited visits, measurement error, a poorly specified mean trajectory, or an unsuitable residual structure can make the components difficult to separate.

The main alternative is not to rename one component but to use a simpler or differently specified model that matches the scientific question and data. A random-intercept-only model allows subjects to have different baselines but not random rates of change. Adding random slopes allows trajectories to differ in rate, but requires enough information to estimate that variation. A model with one undifferentiated error term cannot represent persistent subject-level departures separately from occasion-level noise. More elaborate residual structures or time-varying residual variances may be appropriate when the basic assumptions fail; each requires its own justification.

A common mistake is to call every deviation from the fitted population mean “residual error.” In a mixed model, that deviation includes both \(z_{ij}^{\mathsf T}b_i\) and \(\varepsilon_{ij}\). The correction is to ask whether the deviation represents a subject-level pattern shared across that subject’s observations, an occasion-specific departure, or a combination that the model cannot fully distinguish. Another mistake is to infer that large residual variance means there are no meaningful individual differences: random-effects and residual variation can both be large, and their estimated sizes answer different questions.

Key takeaway: At a given visit, random-effects variation describes how subjects’ latent trajectories differ from the population mean, while residual variation describes occasion-level departures around those trajectories. Under independence, their variances add for a single measurement; the components remain conceptually distinct and depend on the model assumptions.

Check Your Understanding

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

  1. In \(y_{ij}=x_{ij}^{\mathsf T}\beta+z_{ij}^{\mathsf T}b_i+\varepsilon_{ij}\), which term represents occasion-level residual error?
  2. A random-intercept variance is \(6\;(\text{mg/L})^2\), and residual variance is \(10\;(\text{mg/L})^2\). Under the basic independence assumptions, what is the total variance at one visit?
  3. Why can the random-effects contribution vary with time in a random-intercept-and-slope model?
  4. What might a systematic increase in residual spread over time suggest about a constant-residual-variance assumption?

Solutions. 1. The occasion-level error is \(\varepsilon_{ij}\); \(b_i\) represents subject-level random effects. 2. The total is \(6+10=16\;(\text{mg/L})^2\), because the components are independent under the specified assumptions. 3. The random contribution is \(b_{0i}+tb_{1i}\), so its variance depends on \(t\) and on the covariance between intercept and slope. 4. It may indicate that residual variance is not constant over time, so the basic residual specification should be reconsidered rather than assumed adequate.

Clinical Biostats