Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Conditional And Marginal Residuals In Joint Models

Model Diagnostics · Tutorial 593 of 697

Conditional And Marginal Residuals In Joint Models

Distinguish residuals based on estimated subject effects from residuals based on population-averaged predictions, and learn what each can and cannot diagnose.

Advanced 12 min read

What You'll Learn

  • Define conditional and population-marginal residuals for longitudinal outcomes.
  • Distinguish marginal survival probabilities from averages of conditional event risks.
  • Calculate residuals under both targets using hypothetical joint-model data.
  • Explain how random effects can make conditional and marginal residual patterns differ.
  • Identify common diagnostic pitfalls, including censoring and shrinkage of estimated random effects.

Why Two Residual Targets Matter

A joint model uses repeated measurements and event-time information to describe related processes. Its random effects represent subject-specific departures from the population trajectory, and may also link that trajectory to the event hazard. A residual therefore depends on which prediction is being compared with the observation: one tailored to a subject's estimated random effects, or one averaged over the random-effects distribution.

Neither target is universally preferable. Conditional residuals ask whether the fitted model describes observations after accounting for estimated subject differences. Marginal residuals ask whether its population-level predictions describe the data. A model can look adequate under one target and show structure under the other. Interpretation begins by stating exactly what has been conditioned on and what has been averaged out.

Definition: A conditional residual is an observation minus its fitted value conditional on an estimate of that subject's random effects. A population-marginal residual is an observation minus its fitted value averaged over the population distribution of random effects. For an observed longitudinal measurement \(Y_{ij}\), these are \(r^C_{ij}=Y_{ij}-\widehat m_i(t_{ij};\widehat b_i)\) and \(r^M_{ij}=Y_{ij}-\int \widehat m_i(t_{ij};b)f_{\widehat\theta}(b)\,db\), respectively. Here \(\widehat m_i(t;b)\) is the fitted conditional mean, \(\widehat b_i\) is an estimated subject effect, and \(f_{\widehat\theta}\) is the fitted population distribution of those effects.

The Model and the Averaging Operation

For a Gaussian longitudinal marker, a common specification is \(Y_{ij}=m_i(t_{ij};b_i)+\epsilon_{ij}\), where \(m_i(t;b)=x_i(t)^\top\beta+z_i(t)^\top b\), \(b_i\sim N(0,D)\), and \(\epsilon_{ij}\sim N(0,\sigma^2)\). The random effects \(b_i\) describe between-subject variation; the errors describe measurement-level variation. In this basic form the errors are independent of the random effects and independent across visits, conditional on the model covariates and random effects. Extensions can relax the error assumptions.

The marginal fitted mean follows from averaging over the random-effects distribution:

$$ E\{Y_{ij}\mid x_i(t_{ij}),z_i(t_{ij})\} =\int m_i(t_{ij};b)f_{\theta}(b)\,db =x_i(t_{ij})^\top\beta $$

The last equality uses \(E(b_i)=0\) in this linear model. It is not a universal rule to substitute zero for a random effect: for a nonlinear mean or link, the average of \(m_i(t;b)\) generally differs from \(m_i(t;E(b))\). The definition of the marginal prediction is the integral, not a plug-in shortcut.

In a joint model, the event component is often specified conditionally on the same random effects. For example, a proportional hazards model may have \(h_i(t\mid b_i)=h_0(t)\exp\{\gamma^\top w_i+\alpha m_i(t;b_i)\}\), where \(h_0(t)\) is a baseline hazard and the association parameter \(\alpha\) links the marker trajectory to event risk. The longitudinal and event processes are typically assumed independent conditional on the shared random effects and model covariates; the shared effects induce dependence after they are integrated out. Conditional event predictions use a specified \(b_i\); population-marginal predictions integrate over its distribution.

These definitions presume a correctly specified model for the mean, random-effects distribution, and relevant dependence structure. Inference also requires suitable assumptions about censoring, such as censoring being independent of the event process conditional on included information. In practice, parameters and subject effects are estimated, so residuals are diagnostic quantities rather than independent errors with an exact zero mean in every fitted data set.

Worked Example: A Conditional and a Marginal Marker Residual

Suppose a hypothetical linear mixed model has fitted population mean \(10+0.5t\). For one subject, the estimated random intercept is \(\widehat b_i=1.2\). At \(t=2\), the observed measurement is \(Y_{ij}=10.4\). The model has a random intercept, so its conditional mean is \(10+0.5t+b_i\), while its population-marginal mean is \(10+0.5t\), since the random intercept has population mean zero.

Conditional fit. Substituting the time and estimated subject effect gives \(\widehat m_i(2;\widehat b_i)=10+0.5(2)+1.2=12.2\). Thus the conditional residual is \(10.4-12.2=-1.8\) measurement units.

Marginal fit. Averaging over the random-intercept distribution gives \(\widehat m_i^M(2)=10+0.5(2)=11.0\). The marginal residual is \(10.4-11.0=-0.6\) measurement units.

Both calculations are correct, but they answer different questions. The conditional residual says the observation is 1.8 units below the fitted value for this subject's estimated intercept. The marginal residual says it is 0.6 units below the population-average fitted value. The difference is not evidence that one calculation is wrong; it reflects different prediction targets.

Why Conditional Residuals Can Look Smaller

Subject effects are usually estimated from the observed data, often by empirical Bayes or related methods. Because these estimates are informed by the subject's measurements, the conditional fit adapts to that subject. This can reduce apparent between-subject structure in conditional residuals, especially when each subject has few observations and the random effects are shrunk toward zero. A small conditional residual does not by itself show that the population trajectory or random-effects distribution is appropriate.

A simple variance calculation explains the difference in scale between the targets. In the random-intercept model \(Y_{ij}=x_i^\top\beta+b_i+\epsilon_{ij}\), the marginal prediction omits the individual \(b_i\). Under the stated independence and zero-mean assumptions, the marginal prediction error has variance \(D+\sigma^2\), whereas the prediction error conditional on the true \(b_i\) has variance \(\sigma^2\). This follows by adding the variance of the independent random intercept and measurement error:

$$ \operatorname{Var}(Y_{ij}-x_i^\top\beta) =\operatorname{Var}(b_i+\epsilon_{ij}) =D+\sigma^2, \qquad \operatorname{Var}(Y_{ij}-x_i^\top\beta-b_i\mid b_i) =\operatorname{Var}(\epsilon_{ij})=\sigma^2 $$

In actual diagnostics, \(b_i\) is not known, and replacing it with \(\widehat b_i\) adds estimation and shrinkage effects. The calculation is therefore a guide to the targets, not a claim that observed fitted residuals have exactly these variances. It does show why marginal residuals naturally retain between-subject variation that conditional residuals attempt to explain through subject effects.

Worked Example: Averaging Conditional Survival Predictions

Consider a hypothetical two-group random-effects distribution: half the population has a conditional event hazard of \(0.20\) per year, and half has a hazard of \(0.05\) per year. Assume constant hazards over five years, no censoring before five years for the prediction exercise, and no other covariates. For a constant hazard \(\lambda\), conditional survival is \(S(5\mid b)=e^{-5\lambda}\).

For the first group, \(S(5\mid b_1)=e^{-5(0.20)}=e^{-1}=0.3678794\). For the second, \(S(5\mid b_2)=e^{-5(0.05)}=e^{-0.25}=0.7788008\). The population-marginal survival probability is the average of these conditional probabilities:

$$ S^M(5)=0.5e^{-1}+0.5e^{-0.25} =0.5733401\approx0.5733 $$

Therefore the marginal event risk by five years is \(F^M(5)=1-S^M(5)=0.4266599\approx0.4267\). Suppose a subject is observed to have an event by five years and belongs to the first, higher-hazard group. The conditional observed-minus-predicted risk discrepancy is \(1-(1-e^{-1})=e^{-1}=0.3678794\), or about 0.3679. Using the population-marginal risk instead gives \(1-0.4266599=0.5733401\), or about 0.5733. The conditional discrepancy uses the group-specific prediction; the marginal discrepancy uses the population-average prediction.

The marginal survival is not obtained by averaging the hazards and then calculating survival: that would give \(e^{-5(0.125)}=e^{-0.625}\), which is about 0.5353, not 0.5733. Survival is a nonlinear function of the hazard, so the order of averaging and transformation matters.

Event Outcomes, Censoring, and Interpretation

For a clearly defined horizon \(u\), an event-risk residual can be written as observed event status by \(u\) minus predicted event risk by \(u\). Let \(I(T_i\leq u,\delta_i=1)\) indicate an observed event by \(u\), where \(T_i\) is observed follow-up time and \(\delta_i=1\) denotes an event. For a subject whose status through \(u\) is known, define the conditional and marginal versions as

$$ r^C_i(u)=I(T_i\leq u,\delta_i=1)-\{1-S_i(u\mid\widehat b_i)\}, \qquad r^M_i(u)=I(T_i\leq u,\delta_i=1)-\{1-S_i^M(u)\} $$

A positive value means the observed event indicator exceeds the predicted risk; a negative value means it is below the predicted risk. Under a correctly specified model and complete ascertainment through \(u\), the expected observed indicator equals the predicted risk for the corresponding target, so its residual has expectation zero before parameter-estimation effects. This statement is not a justification for treating a censored subject as event-free through \(u\).

If a subject is censored before \(u\) without a prior event, their event status at \(u\) is unknown. Setting the observed indicator to zero and computing the expression above would misclassify missing horizon status as known non-event status. Censoring-aware residual methods are needed for such data; the formula is directly interpretable only when status through the horizon is observed. Similarly, an event-time difference such as “observed time minus predicted time” is not an automatic residual under right censoring.

Worked Example: A Random-Slope Subject at Two Visits

Suppose a hypothetical marker model has population mean \(4+0.6t\) and subject-specific random intercept and slope estimates \(\widehat b_{0i}=0.7\) and \(\widehat b_{1i}=-0.2\). Thus the conditional fitted mean is \(4+0.6t+0.7-0.2t\). The subject's observed measurements are 5.4 at \(t=1\) and 5.0 at \(t=2\). Assume the random effects are centered at zero, so the population-marginal fitted mean is \(4+0.6t\).

At \(t=1\), the conditional fit is \(4+0.6+0.7-0.2=5.1\), giving conditional residual \(5.4-5.1=0.3\) measurement units. The marginal fit is \(4+0.6=4.6\), giving marginal residual \(5.4-4.6=0.8\) units.

At \(t=2\), the conditional fit is \(4+1.2+0.7-0.4=5.5\), giving conditional residual \(5.0-5.5=-0.5\) units. The marginal fit is \(4+1.2=5.2\), giving marginal residual \(5.0-5.2=-0.2\) units. The conditional residuals describe deviations around this subject's estimated trajectory; the marginal residuals also reflect this subject's departure from the population trajectory. Neither pair alone establishes whether the slope structure is adequate, but comparing them clarifies which level of variation a diagnostic pattern concerns.

Comparing the Targets and Diagnosing Misfit

Residual targetPrediction usedQuestion it helps addressImportant limitation
ConditionalFitted value given an estimated subject effectDoes the fitted subject-specific trajectory or hazard leave systematic residual structure?Estimated effects use the subject's data and can absorb or shrink apparent discrepancies.
Population-marginalFitted value integrated over the population random-effects distributionAre population-average predictions consistent with the observations?Residuals retain real between-subject heterogeneity, which is not necessarily model error.
Posterior-averaged subject predictionFitted value integrated over a subject-specific distribution of random effects given available informationWhat prediction averages over uncertainty about a particular subject's effect?It depends on which information conditions that distribution; it is not the same target as the population marginal mean.

The third row is worth distinguishing from the usual population-marginal residual. A posterior-averaged prediction integrates over uncertainty about a particular subject's random effect, conditional on specified information. It can be useful when prediction is the aim, but it is not simply an average over the population distribution. For nonlinear event predictions, integrating conditional survival over a posterior distribution can differ from evaluating survival at the posterior mean random effect.

Look for patterns in each residual target that correspond to its question. A trend over time in conditional marker residuals may suggest the subject-specific mean trajectory leaves structure unexplained. A broad shift or excess spread in marginal residuals may instead signal a problem with population calibration or the random-effects distribution. In event diagnostics, systematic differences between observed event frequencies and conditional or marginal predicted risks can point to different failures: a subject-level association problem versus a population-level risk-prediction problem. These are clues, not diagnoses by themselves; sampling variation, parameter uncertainty, censoring, and unmodeled covariates can produce similar patterns.

A frequent pitfall is to treat every marginal residual far from zero as an individual model failure. Marginal residuals include between-subject variation by construction. The correction is to ask whether the pattern is systematic and whether it is unexpected under the marginal model, rather than demanding that each subject's observation closely match a population-average prediction. The converse pitfall is to regard small conditional residuals as proof of population adequacy: subject-specific fitted effects can make those residuals small even when the population distribution or average prediction is wrong.

A second pitfall is to average quantities in the wrong order. In a joint model, averaging conditional survival probabilities is generally not the same as computing survival from an averaged hazard or from a mean random effect. A third is to use outcome information that would not have been available for the prediction being evaluated. When residuals are intended to assess prospective prediction, the fitted subject effect and prediction must be based only on the information available at the stated prediction time. In-sample diagnostic residuals can use observed outcomes to fit the model, but should not be described as independent validation predictions.

Conditional and marginal residuals are complementary rather than competing alternatives. Conditional residuals focus on fit after accounting for estimated subject heterogeneity; marginal residuals focus on population-level fit including that heterogeneity. Neither replaces checking whether the model assumptions are plausible, whether estimates are stable, or whether censoring and observation processes have been handled appropriately. The appropriate residual depends on the scientific and predictive target.

Key takeaway: Always name the prediction target before interpreting a residual. Conditional residuals subtract a subject-specific fitted value based on estimated random effects; population-marginal residuals subtract a prediction integrated over the random-effects distribution. Their differences are often substantive, not arithmetic errors.

Check Your Understanding

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

  1. In a linear random-intercept model with population mean 8 and an estimated subject intercept of 1.5, an observed measurement is 9.0. Find the conditional and population-marginal residuals.
  2. Why can the marginal survival probability differ from survival calculated at the mean random effect?
  3. A subject is censored at year 3, with no prior event. Can the subject's observed event indicator by year 5 be set to zero when calculating a five-year risk residual? Explain.
  4. What question is a conditional longitudinal residual designed to address, and what is one reason it may look deceptively small?

Solutions. (1) The conditional fitted value is \(8+1.5=9.5\), so the conditional residual is \(9.0-9.5=-0.5\) measurement units. The marginal fitted value is 8, so the population-marginal residual is \(9.0-8=1.0\) unit. (2) Survival is a nonlinear function of the random effect through the hazard; in general, averaging conditional survival is not equal to evaluating survival at the mean effect. (3) No. Event status at year 5 is unknown for someone censored at year 3 without an event, so coding the person as event-free through year 5 would be incorrect. (4) It asks whether observations depart systematically from the fitted subject-specific trajectory after accounting for estimated random effects. It may look small because the same subject's measurements helped estimate the random effect, allowing the fitted trajectory to adapt to those measurements.

Clinical Biostats