Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Spline Complexity for Generalized Responses

Flexible Trajectories and Non-Gaussian Responses · Tutorial 497 of 697

Spline Complexity for Generalized Responses

You will learn to compare spline complexity for generalized marker trajectories using joint-model fit, predictive performance, uncertainty and stability rather than choosing the most flexible curve by default.

Advanced 12 min read

What You'll Learn

  • Specify spline trajectories for non-Gaussian markers on the link scale.
  • Distinguish spline degree, knot count and penalty strength.
  • Compare unpenalized models using likelihood-based criteria.
  • Use subject-level validation to tune smoothing penalties.
  • Assess uncertainty and resampling stability alongside fit.
  • Recognize convergence and model-comparison pitfalls in joint models.

Why Spline Complexity Needs Careful Comparison

A flexible trajectory can represent changes in a binary, ordinal, count or bounded biomarker that a straight line cannot. But adding spline basis functions also adds opportunities to fit sampling noise. In a joint model, this choice matters twice: it shapes the longitudinal mean and can change the estimated association between the latent marker trajectory and event risk. The goal is therefore not to maximize flexibility, but to choose a trajectory that fits adequately, gives defensible uncertainty, and remains stable under reasonable perturbations of the data or specification.

The response family and link should be chosen for the marker’s type. Spline complexity is a separate decision: it controls the shape of the predictor over time, not the response distribution. For instance, a binary marker may have a spline predictor on the logit scale; its predicted probability is obtained by applying the inverse link. Candidate models should use the same response family, link, covariates, and event-model structure when the purpose is to compare trajectory complexity.

Definition: A spline trajectory represents a time-varying predictor as a linear combination of basis functions, \(f(t)=\mathbf{B}(t)^\top\boldsymbol{\theta}\). Its complexity is influenced by the polynomial degree, the number and placement of knots, and—when used—the strength of a smoothing penalty. These are distinct choices: degree controls the polynomial pieces, knots control where pieces can change, and the penalty controls how strongly coefficient combinations associated with curvature are shrunk.

Candidate Trajectories in a Joint Model

For subject \(i\) at visit \(j\), a generalized longitudinal submodel can be written as

$$ g\{\mu_i(t_{ij})\} = \mathbf{x}_{ij}^{\top}\boldsymbol{\beta} + \mathbf{B}(t_{ij})^{\top}\boldsymbol{\theta} + \mathbf{z}_{ij}^{\top}\mathbf{b}_i, \qquad \mu_i(t_{ij})=E(Y_{ij}\mid\mathbf{b}_i). $$

Here \(g\) is the link, \(\mathbf{B}(t)\) is the spline basis, \(\boldsymbol{\theta}\) contains its coefficients, and \(\mathbf{b}_i\) denotes subject-specific random effects. For example, with a binary marker, \(g\) may be the logit link and \(\mu_i(t)\) is a conditional probability. The event component may use the latent marker value in a hazard such as

$$ \lambda_i(t\mid\mathbf{b}_i) = \lambda_0(t)\exp\{\mathbf{w}_i^\top\boldsymbol{\gamma} +\alpha m_i(t)\}, $$

where \(m_i(t)\) is the specified latent marker feature. To isolate the effect of spline complexity, keep the event model and the definition of \(m_i(t)\) unchanged across candidates. A different trajectory can nevertheless alter \(\hat{\alpha}\), because it changes the estimated latent marker history.

A piecewise polynomial spline of degree \(d\) has polynomial pieces joined at knots; with the usual B-spline construction, the basis dimension depends on both \(d\) and the knot sequence. Greater degree or more knots can make a richer shape possible, but neither guarantees a better model. A smoothing penalty offers another route: retain a sufficiently rich basis and discourage excessive curvature. For a coefficient vector \(\boldsymbol{\theta}\), a common penalized objective is

$$ \ell_{\mathrm{pen}}(\boldsymbol{\theta}) = \ell(\boldsymbol{\theta})-\frac{\lambda}{2} \boldsymbol{\theta}^{\top}\mathbf{K}\boldsymbol{\theta}, $$

where \(\ell\) is the relevant log likelihood, \(\mathbf{K}\) is a penalty matrix, and \(\lambda\geq 0\) controls penalty strength. The penalty is often constructed to penalize curvature while leaving selected low-order components, such as a constant or linear trend, unpenalized. A larger \(\lambda\) then means more shrinkage in the penalized directions.

What the Penalty Does: A Short Derivation

The effect of a quadratic penalty is easiest to see in a local weighted least-squares approximation, such as one used during iteratively reweighted fitting of a generalized model. Let \(\mathbf{z}\) be the working response, \(\mathbf{B}\) the evaluated basis matrix, and \(\mathbf{W}\) the working weight matrix. The penalized estimate minimizes

$$ (\mathbf{z}-\mathbf{B}\boldsymbol{\theta})^\top \mathbf{W}(\mathbf{z}-\mathbf{B}\boldsymbol{\theta}) + \lambda\boldsymbol{\theta}^\top\mathbf{K}\boldsymbol{\theta}. $$

Differentiating with respect to \(\boldsymbol{\theta}\), setting the derivative to zero, and solving gives

$$ (\mathbf{B}^{\top}\mathbf{W}\mathbf{B}+\lambda\mathbf{K}) \hat{\boldsymbol{\theta}} = \mathbf{B}^{\top}\mathbf{W}\mathbf{z}, \qquad \hat{\boldsymbol{\theta}} = (\mathbf{B}^{\top}\mathbf{W}\mathbf{B}+\lambda\mathbf{K})^{-1} \mathbf{B}^{\top}\mathbf{W}\mathbf{z}. $$

Thus the fitted working values are \(\mathbf{S}_{\lambda}\mathbf{z}\), where \(\mathbf{S}_{\lambda}=\mathbf{B}(\mathbf{B}^{\top}\mathbf{W}\mathbf{B}+\lambda\mathbf{K})^{-1}\mathbf{B}^{\top}\mathbf{W}\). The effective degrees of freedom are commonly approximated by \(\mathrm{tr}(\mathbf{S}_{\lambda})\). They generally decrease as the penalty suppresses more flexible directions, though the exact behavior depends on the design and penalty matrix. In a generalized joint model this is a local approximation, not an exact universal degrees-of-freedom formula. It explains why counting all basis coefficients as freely estimated parameters can misstate the complexity of a penalized fit.

Comparing Fit Without Confusing Complexity Measures

For unpenalized candidate joint models fitted to the same observations, the maximized marginal log likelihood can be compared using information criteria. With \(k\) estimated parameters and \(n\) independent subjects, the familiar forms are

$$ \mathrm{AIC}=-2\ell+2k, \qquad \mathrm{BIC}=-2\ell+k\log(n). $$

The likelihood here should reflect the joint model, including the longitudinal and event data and integration over subject-specific random effects. A lower criterion is preferred among the candidates being compared. For penalized models, a criterion must account appropriately for effective complexity; simply inserting the number of basis coefficients into an unpenalized AIC formula is not generally justified. The likelihood used for scoring should also be the likelihood, not merely the penalized objective value.

Worked Example: Comparing Degree and Knot Choices by AIC

Suppose 180 hypothetical patients have repeated binary marker measurements and event follow-up. Four joint models use the same logit link, covariates, random-effects structure and event association, but different unpenalized spline specifications. Their maximized marginal log likelihoods and parameter counts are as follows.

Trajectory specification\(\ell\)\(k\)AIC
Linear, no internal knot-812.4181660.8
Quadratic, 2 internal knots-798.1211638.2
Cubic, 3 internal knots-795.0251640.0
Cubic, 5 internal knots-790.8301641.6

For the quadratic candidate, \( \mathrm{AIC}=-2(-798.1)+2(21)=1596.2+42=1638.2 \). For the cubic model with 5 internal knots, \( \mathrm{AIC}=-2(-790.8)+2(30)=1581.6+60=1641.6 \). The last model has the largest likelihood, but its additional parameters more than offset the gain under AIC. Among these four candidates, the quadratic model with 2 internal knots has the smallest AIC. This comparison is meaningful only if the stated models converged to comparable likelihood solutions and were fitted to the same data.

Tuning a Smoothing Penalty With Validation

When candidates share a rich basis and differ in \(\lambda\), subject-level cross-validation can assess predictive performance without relying only on an in-sample fit. In each fold, fit the joint model on training subjects and evaluate a prespecified predictive log score for held-out subjects. A joint marginal predictive score integrates over the random effects for a new subject; it should not use that subject’s held-out marker values to estimate their random effects before scoring those same values. Splitting visits from the same patient across training and validation sets can leak subject-specific information and give an overly optimistic assessment.

Choose the validation target to match the scientific use. A joint predictive score can include marker and event information. A marker-only score answers a narrower question about marker prediction and should not be described as assessing the full joint model. Repeated folds or repeated partitions help quantify variation in the score. A one-standard-error rule is a practical simplicity preference: choose the most strongly penalized candidate whose mean score is within one estimated standard error of the best mean score. It is a selection convention, not a test that models have equal predictive performance.

Worked Example: Selecting Penalty Strength by Subject-Level Validation

In a hypothetical analysis, a fixed spline basis is fitted with four penalty values. Five-fold validation is repeated, with folds formed by patient. The table reports mean joint log predictive score per held-out patient (higher is better), its estimated standard error, and approximate effective degrees of freedom.

\(\lambda\)Mean scoreSEEffective df
0.1-4.570.127.1
1-4.610.095.8
10-4.650.104.2
100-4.820.112.5

The best mean score is \(-4.57\), at \(\lambda=0.1\), and its standard error is \(0.12\). The one-standard-error threshold is \(-4.57-0.12=-4.69\); scores at least this high remain eligible. The candidates with \(\lambda=0.1\), \(1\), and \(10\) meet that threshold, while \(\lambda=100\) does not. The most strongly penalized eligible candidate is \(\lambda=10\), with 4.2 effective degrees of freedom, so the one-standard-error rule selects it. This favors a simpler curve with validation performance close to the best observed score; it does not establish that \(\lambda=10\) is the uniquely correct value.

Uncertainty and Stability Are Part of the Choice

Fit scores alone do not show whether a complicated curve is well determined. Examine uncertainty in the estimated trajectory on the scale relevant to interpretation, and check the estimated event-association parameter under the candidate specifications. For a binary marker, for example, uncertainty may be shown for predicted probabilities as well as for the link-scale predictor. These quantities are related by the inverse link but are not interchangeable. Uncertainty calculations should reflect the fitted joint model and its dependence structure; treating repeated observations as independent can understate uncertainty.

Stability asks whether conclusions change substantially under reasonable perturbations, such as resampling subjects, modestly changing knot locations, or changing the number of knots by one. A subject-level bootstrap can summarize the spread of an estimated probability at a clinically relevant time or of the event-association estimate. Instability is a warning to inspect the data support, convergence and model specification; it is not automatic proof that the more flexible model is wrong. Conversely, a narrow interval is not a reason by itself to prefer a model if its shape is implausibly constrained or its predictive fit is poor.

Worked Example: Using Bootstrap Stability Alongside Fit

Consider three hypothetical joint models for a bounded marker, with identical response family, link and event model. Each is refitted in 200 patient-level bootstrap samples. At month 9, the models yield the following estimated mean marker values and bootstrap standard deviations; the association estimates are on the log-hazard scale.

SpecificationEstimated marker mean at month 9Bootstrap SDEstimated association \(\hat{\alpha}\)Bootstrap SD of \(\hat{\alpha}\)
Quadratic, 2 knots0.680.060.590.14
Cubic, 3 knots0.720.080.640.19
Cubic, 7 knots0.790.170.910.48

The seven-knot fit gives the largest estimated month-9 marker mean and association, but it is also much less stable across resamples: the estimated association has bootstrap SD \(0.48\), compared with \(0.14\) for the quadratic fit. This does not prove the seven-knot estimate is biased, and the bootstrap SD is not itself a model-selection test. It does signal that the implied event association is sensitive to the data sample. A defensible decision would consider this instability alongside joint fit and validation scores, then report the sensitivity rather than presenting a single selected curve as certain.

Diagnostics, Alternatives, and Common Pitfalls

Before interpreting a complexity comparison, verify that every candidate uses the same subjects, response and event definitions, and likelihood integration settings. Check convergence messages, gradients, Hessian behavior, and whether different starting values lead to materially different solutions. A higher-dimensional spline can make likelihood optimization and integration more difficult; an apparent fit improvement may reflect a poorly converged comparison. Plot estimated trajectories and uncertainty on the link and response scales, as appropriate, and inspect whether changes in the estimated event association are consequential.

The main alternatives answer different questions. A small set of prespecified polynomial or low-knot models offers transparent, discrete comparisons, often using AIC or BIC when likelihood assumptions and parameter counting are appropriate. A penalized spline searches a continuum of smoothness levels and can be tuned by validation or a suitable information criterion using effective complexity. Cross-validation emphasizes predictive performance, while information criteria trade fit against complexity using an approximation based on likelihood and parameter count. None substitutes for checking the response distribution, link, event model or adequacy of the observed time coverage.

  • Mistake: “The largest knot count has the best fit, so it is the best model.” The unpenalized likelihood cannot decrease merely because a nested model is made more flexible, so its increase alone does not balance added complexity. Compare an appropriate penalized criterion or validation score, and assess uncertainty and stability.
  • Mistake: treating \(\lambda\) as another knot count. Knot count changes the available basis; \(\lambda\) shrinks selected combinations within a basis. State both the basis and penalty when describing a fitted trajectory.
  • Mistake: using visits as independent validation units. Measurements from one subject share latent effects. Split by subject for new-subject prediction, and integrate over random effects in the held-out predictive score.
  • Mistake: selecting the model with the narrowest intervals. Overly restrictive curves can produce narrow uncertainty while missing genuine temporal structure. Consider fit and calibration as well as uncertainty.

This comparison does not eliminate the need for scientific judgment. Sparse observations in parts of follow-up can make different curves hard to distinguish, and a selected model is still conditional on the chosen response family, link, random-effects structure and event association. Detailed boundary behavior and spline overfitting require particular care where data are limited near the ends of follow-up. Report the basis, degree, knot locations or selection rule, penalty and tuning procedure, criterion values, and important sensitivity findings so that the complexity choice can be assessed and reproduced.

Check Your Understanding

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

  1. What are the separate roles of spline degree, knot count and penalty strength?
  2. Two unpenalized joint models have log likelihoods \(-500\) and \(-493\), with 20 and 25 parameters respectively. Compute their AIC values and identify the lower-AIC model.
  3. Why should cross-validation folds for new-subject prediction be formed by patient rather than by visit?
  4. A more flexible model has a higher estimated event association and much larger bootstrap variability. What does this suggest, and what does it not prove?

Solutions. (1) Degree controls the polynomial pieces, knots control where pieces can change, and the penalty shrinks selected coefficient directions within a chosen basis. (2) The first AIC is \(-2(-500)+2(20)=1040\); the second is \(-2(-493)+2(25)=986+50=1036\). The second model has the lower AIC by 4. (3) Visits from the same patient share latent subject-specific information; splitting them across folds can leak that information and overstate prediction for a new patient. (4) It suggests the event association is sensitive to the sample and warrants checks of fit, convergence and specification. It does not by itself prove the flexible model is biased or that the less flexible model is correct.

Clinical Biostats