Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Cross-Validation for Joint-Model Prediction

Calibration and Prediction Validation · Tutorial 573 of 697

Cross-Validation for Joint-Model Prediction

Use subject-level cross-validation to estimate the predictive performance of a prespecified joint model without letting held-out subjects influence model fitting.

Advanced 12 min read

What You'll Learn

  • Explain why all records from one subject must remain in the same fold.
  • Separate model fitting from prediction using held-out subjects’ permitted measurement histories.
  • Calculate and aggregate subject-level validation losses across folds.
  • Identify leakage from preprocessing, model fitting, or use of future measurements.
  • Describe what cross-validation estimates and how it differs from apparent performance and a single holdout split.

Why Cross-Validate at the Subject Level?

A joint model uses longitudinal measurements and time-to-event outcomes together. Its predictions depend on estimated model parameters, and often on subject-specific latent effects. Evaluating predictions on the same subjects used to estimate those quantities can make performance look better than it will be for new subjects. Cross-validation addresses this optimism by repeatedly fitting the model on one set of subjects and evaluating predictions on a separate set.

The unit of splitting matters. A subject may contribute many longitudinal records but only one event or censoring time. If some of that subject’s records enter the training data while other records are treated as held out, the held-out predictions are not independent of the training process. A model may already have learned information about that person. The solution is to assign each subject, with all of their records and survival outcome, to exactly one fold.

Definition: In subject-level \(K\)-fold cross-validation, the \(n\) subjects are divided into \(K\) disjoint folds. For each fold, the joint model is fitted using subjects in the other \(K-1\) folds, and predictions are generated for subjects in the held-out fold. A validation metric is calculated from these held-out predictions and outcomes. Each subject is held out once.

Write subject \(i\)’s longitudinal measurements as \(Y_i(t)\), its observed event or censoring time as \(T_i\), and its event indicator as \(\Delta_i\), where \(\Delta_i=1\) indicates an observed event and \(\Delta_i=0\) indicates censoring. Let \(I_k\) be the set of subjects in fold \(k\). The training set for that fold is all subjects not in \(I_k\). The model is refitted from the beginning for each training set.

Define the Prediction Task Before Splitting

Cross-validation evaluates a particular prediction task, not an abstract model in isolation. Specify the prediction time, the survival quantity to predict, and what information about a held-out subject is available at that time. For example, a task may predict survival through a fixed horizon \(u\) using only information available at baseline, or predict survival beyond a landmark time \(t_0\) using measurements recorded on or before \(t_0\).

For a landmark prediction, write the held-out subject’s available history as \(H_i(t_0)\). A prediction might be the conditional survival probability \(\hat S_i(u\mid t_0,H_i(t_0))\), for \(u>t_0\). The history may be used to infer a subject-specific latent effect if that matches the intended prediction procedure. But measurements recorded after \(t_0\), or the subject’s future event outcome, must not be used to construct the prediction. At baseline, no follow-up history is available, so a prediction must instead use baseline information and the model’s population distribution for latent effects.

This distinction prevents a subtle form of leakage: withholding a subject from parameter estimation does not by itself make a prediction valid if future information from that subject is then used to personalize it. The allowed information must match the real use of the prediction.

Worked Example: Assigning Subjects to Folds

Suppose a hypothetical dataset contains 12 subjects, each with several longitudinal measurements and one survival outcome. For a four-fold analysis, each fold contains three subjects.

Assign subjects 1–3 to fold 1, 4–6 to fold 2, 7–9 to fold 3, and 10–12 to fold 4. When fold 2 is held out, the training subjects are 1–3 and 7–12: \(3+6=9\) subjects. All longitudinal records and the survival outcome for subjects 4, 5, and 6 are excluded from fitting.

The model fitted on those nine subjects generates predictions for subjects 4, 5, and 6 using only the information allowed by the prediction task. The process is repeated with each fold held out in turn. Thus each subject receives predictions from a model that was not fitted using that subject’s data.

What Must Be Refit Within Each Fold?

Every data-dependent part of the modeling pipeline must be learned using the training subjects only. This includes the joint-model parameters, baseline hazard estimates, longitudinal and survival submodel parameters, and any estimated covariance or random-effects distribution. If the pipeline includes imputation, scaling, variable screening, or other preprocessing, its learned quantities must also come from the training fold. Apply those training-derived quantities to the held-out fold without re-estimating them there.

For a fixed, prespecified model, the essential procedure is:

1
Fix the task and folds.
Specify the prediction horizon, information available for each prediction, metric, and subject-level fold assignment.
2
Fit within the training subjects.
For each fold, estimate the joint model and all training-dependent preprocessing using only subjects outside that fold.
3
Predict held-out subjects.
Use the fitted model and only the permitted information for each held-out subject to generate predictions.
4
Score and aggregate.
Compare held-out predictions with held-out outcomes using the specified metric, then combine subject-level losses across folds.

The cross-validated estimate for a subject-level loss \(L_i\) is the average of the losses from the predictions made while each subject was held out:

$$ \widehat{R}_{CV}=\frac{1}{n}\sum_{k=1}^{K}\sum_{i\in I_k}L_i $$

For a loss such as the Brier score, smaller values indicate better predictions. For a score defined so that larger values are better, retain that score’s direction when interpreting the result. If folds have unequal sizes, the pooled subject-level average above weights each fold according to its number of subjects; simply averaging fold means would give equal weight to folds of different sizes.

Worked Example: A Held-Out Brier Score

Consider four hypothetical held-out subjects with fully observed event status at a fixed horizon. Let \(Z_i=1\) if the event occurred by the horizon and \(Z_i=0\) otherwise. The model’s predicted event risks are 0.20, 0.40, 0.70, and 0.80; the observed indicators are 1, 0, 1, and 0.

For this uncensored example, the subject-level Brier loss is \((Z_i-\hat p_i)^2\), where \(\hat p_i\) is predicted event risk. The four losses are:

$$ (1-0.20)^2=0.64,\quad (0-0.40)^2=0.16,\quad (1-0.70)^2=0.09,\quad (0-0.80)^2=0.64. $$

Their mean is \((0.64+0.16+0.09+0.64)/4=1.53/4=0.3825\). The cross-validated Brier score for these four subjects is therefore 0.3825, a dimensionless measure of squared prediction error. It is not a measure of the model’s performance on its training data.

With censoring before the horizon, event status by that horizon may be unknown for some subjects. The ordinary squared-error calculation above is then not sufficient; use an appropriate censoring-adjusted metric, such as an inverse-probability-weighted Brier score, with its censoring assumptions and estimation procedure specified.

Why the Cross-Validation Estimate Has This Form

The justification is that each subject’s loss is evaluated using a fit that excludes that subject. Under independent, exchangeable sampling of subjects from the target population, a randomly assigned held-out fold behaves like a sample of new subjects relative to the model fitted on the remaining subjects. The average held-out loss therefore estimates predictive risk for the fitting procedure trained on approximately \(n(K-1)/K\) subjects.

More precisely, if a fixed fitting procedure applied to a training sample \(D\) produces predictions \(\hat f_D\), its expected risk is the expected loss on a new subject drawn from the same target population. For each fold, the held-out subjects approximate such new subjects relative to that fold’s training data. Averaging their losses estimates the procedure’s risk. This argument requires that the held-out outcomes are used for scoring, not for choosing or altering that fold’s fitted model.

Cross-validation does not exactly estimate the risk of a model fitted on all \(n\) subjects: each fold’s model uses fewer than \(n\) subjects. With fewer training subjects, performance may be slightly worse than that of the final fit using all available data. The estimate is also conditional on the modeling procedure and prediction task that were evaluated.

Worked Example: Weighting Unequal Fold Sizes

Suppose a hypothetical eight-subject analysis has three held-out folds of sizes 3, 3, and 2. Their mean subject-level losses are 0.20, 0.30, and 0.10, respectively. The pooled cross-validated loss is:

$$ \widehat{R}_{CV} =\frac{3(0.20)+3(0.30)+2(0.10)}{8} =\frac{0.60+0.90+0.20}{8} =\frac{1.70}{8} =0.2125. $$

An unweighted average of the three fold means would be \((0.20+0.30+0.10)/3=0.20\). That calculation gives the two-subject fold the same weight as either three-subject fold, so it is not the overall mean subject-level loss. The pooled value, 0.2125, gives each of the eight subjects equal weight.

Assumptions, Diagnostics, and Common Failure Modes

The interpretation of ordinary subject-level cross-validation relies on several conditions. Subjects should be independent sampling units for the intended target population, or the folds should otherwise respect the dependence structure. The folds should represent the prediction setting of interest. The model must be fitted successfully in each training set, and censoring must be handled appropriately by any metric that requires it. For landmark predictions, the recorded history used to personalize predictions must stop at the landmark.

Inspect the fold assignments and model fits rather than treating the final average as sufficient evidence. Check that every subject appears in exactly one held-out fold, that no subject contributes records to both training and held-out sets, and that each fold has enough events and follow-up for stable fitting. Record convergence warnings, boundary estimates, and failed fits. A metric calculated only from folds where fitting succeeded can be misleading if failure is related to the data or outcome; report failures and address them transparently.

Other warning signs include implausibly strong performance relative to the apparent estimate, predictions that use measurements after the stated prediction time, or preprocessing that was estimated using all subjects. A large difference between folds may reflect instability, uneven event counts, or genuine differences in their held-out subjects. The folds are not independent replications: their training sets overlap, so their metric values should not be treated as independent observations for a routine standard-error calculation.

  • Splitting measurement rows instead of subjects. This puts information about one person in both sets. Assign the whole subject to one fold.
  • Fitting once on all subjects. Predictions from that fit are apparent predictions, not cross-validated predictions. Refit the joint model separately for every training fold.
  • Using held-out outcomes to revise the fit. Held-out outcomes are for scoring. Do not use them to alter model parameters or the prediction pipeline for that fold.
  • Using future history for a landmark prediction. This leaks information unavailable at the prediction time. Restrict subject-specific updating to the permitted history.

Cross-validation differs from apparent performance because the latter evaluates predictions on the fitting data. It differs from a single holdout split because each subject is evaluated once rather than only the subjects assigned to one test set, though a single split may be useful when a sufficiently large independent test sample is available. Bootstrap optimism correction is another internal-validation approach; it estimates and corrects optimism using bootstrap resamples rather than fold-specific fits. Each approach has its own sampling variability and assumptions.

Use cross-validation to assess a prespecified model-building procedure. If the same cross-validation results are also used to choose among many models or tuning options, the reported best performance can be optimistic. The selection problem requires a separate validation design; it should not be resolved by interpreting the selected model’s same cross-validation score as an unbiased final estimate.

Key takeaway: A valid cross-validated prediction for subject \(i\) comes from a joint-model fit that excluded all of subject \(i\)’s records and outcome, and uses only information that would be available for \(i\) at the stated prediction time.

Check Your Understanding

Answer each question, then compare with the concise solutions below.

  1. Why must all longitudinal records for one subject be assigned to the same fold?
  2. At landmark time \(t_0\), may a prediction use a measurement recorded after \(t_0\) to estimate the held-out subject’s latent effect? Explain.
  3. Three folds contain 4, 4, and 2 subjects and have mean losses 0.15, 0.25, and 0.40. Calculate the pooled cross-validated loss.
  4. What training sample size does \(K\)-fold cross-validation most directly assess, and why might it differ from the final model’s training size?

Solutions. (1) Otherwise the model can learn from one part of a subject’s data and be evaluated on another part, creating leakage. (2) No; only information available by \(t_0\) may be used for that prediction. (3) \([4(0.15)+4(0.25)+2(0.40)]/10=(0.60+1.00+0.80)/10=0.24\). (4) Each fold’s model is trained on approximately \(n(K-1)/K\) subjects, fewer than the final fit on all \(n\), so its estimated performance need not exactly equal the final model’s performance.

Clinical Biostats