Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Random-Effects Representations of Spline Trajectories

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

Random-Effects Representations of Spline Trajectories

Learn to separate population-level spline curvature from subject-specific random departures, and see how a spline penalty becomes a random-effects distribution.

Advanced 12 min read

What You'll Learn

  • Write a longitudinal trajectory using fixed spline terms and random effects.
  • Distinguish shared population-level smoothing coefficients from subject-specific spline deviations.
  • Relate a quadratic spline penalty to a Gaussian random-effects distribution.
  • Calculate fitted values and covariance contributions under a spline mixed model.
  • Recognize assumptions, diagnostics, and limitations of random-effects spline representations.

Why Separate Population Curvature From Subject Departures?

A flexible longitudinal trajectory must describe both the average pattern over time and the ways individuals may depart from it. Splines provide flexible time functions, while random effects provide a probability model for correlated departures. These roles can be combined, but the word “random” can be misleading: a spline coefficient treated as a random effect may represent population-level smoothing, not an individual subject’s deviation.

The earlier material on spline bases established how a time function can be built from basis functions. Here the focus is how to assign those basis coefficients to different levels of a longitudinal model. Keeping the levels distinct matters in joint models because an estimated trajectory may later be used to characterize a subject’s biomarker history.

Definition: A fixed spline component is a linear combination of spline basis functions with coefficients that describe the population trajectory. A subject-specific random spline component is a subject-level departure, expressed through basis functions with random coefficients that vary across subjects. A population-level penalized spline component is a flexible shared trajectory represented using random-effect machinery to regularize its curvature; it is not a separate deviation for every subject.

A Hierarchy for Spline Trajectories

For subject \(i\) at observation time \(t_{ij}\), consider a continuous longitudinal outcome \(y_{ij}\). A useful Gaussian model is

$$ y_{ij} = \eta_i(t_{ij}) + \epsilon_{ij}, \qquad \eta_i(t) = x_i(t)^\top\gamma + B(t)^\top\beta + W(t)^\top u + q(t)^\top b_i . $$

Here \(x_i(t)^\top\gamma\) represents covariate effects, \(B(t)^\top\beta\) is the fixed population spline, and \(W(t)^\top u\) is an optional shared penalized spline component. The vector \(b_i\) gives subject \(i\)’s random coefficients, with basis \(q(t)\). A common set of assumptions is

$$ b_i \sim N(0,D), \qquad u \sim N(0,\tau^2 I), \qquad \epsilon_{ij}\sim N(0,\sigma^2). $$

The subject effects are independent across subjects and independent of the residual errors; the shared spline coefficients and subject effects are also assumed independent in this formulation. Conditional on the shared spline and subject effects, the errors are independent with constant variance. These assumptions are modeling choices, not consequences of using a spline basis. In particular, a covariance structure other than \(\tau^2 I\) can be specified when the penalty requires it.

The shared coefficient vector \(u\) is common to the cohort. It represents flexibility in the population curve, with its distribution controlling how much that curve can depart from a simpler fixed form. In contrast, each \(b_i\) is drawn separately for a subject. A random intercept or slope is one possible \(q(t)^\top b_i\); a richer basis can allow subject-specific departures to vary nonlinearly over time.

Key distinction: A random-effect representation is a mathematical way to express a penalty and its uncertainty. It does not, by itself, make a coefficient subject-specific. The index and sharing structure determine the interpretation: \(u\) is shared, whereas \(b_i\) varies by subject.

How a Spline Penalty Becomes a Random Effect

A common spline fit balances data fit against curvature. In a simple penalized least-squares formulation, suppose \(f(t)=B_0(t)^\top\beta+W(t)^\top u\), where \(B_0\) spans the unpenalized part of the function and \(W\) spans the penalized part. For observations \(y_k\) at times \(t_k\), one minimizes

$$ \sum_k \{y_k-f(t_k)\}^2 + \lambda u^\top u. $$

The first term rewards agreement with the observations; the second discourages an unnecessarily large penalized component. Now suppose instead that the conditional data model has independent Gaussian errors with variance \(\sigma^2\), and that \(u\sim N(0,\tau^2 I)\). Ignoring constants, minus twice the log likelihood for the data and the density of \(u\) is

$$ \frac{1}{\sigma^2}\sum_k \{y_k-f(t_k)\}^2 + \frac{1}{\tau^2}u^\top u. $$

Multiplying this expression by \(\sigma^2\), which does not change its minimizer, gives the penalized least-squares objective with

$$ \lambda = \frac{\sigma^2}{\tau^2}. $$

Thus a larger penalty corresponds to a smaller variance for the spline’s random coefficients: the population curve is constrained to stay closer to its unpenalized part. This establishes the mixed-model representation for the identity-penalty case. More generally, a quadratic penalty \(u^\top K u\) can be represented by a Gaussian coefficient distribution whose precision matrix is proportional to \(K\), after handling any unpenalized directions separately. If \(K\) has a null space, those directions must not be treated as ordinary penalized random coefficients without accounting for that null space.

1
Identify the function levels.
Decide which basis terms describe the population curve, which are shared penalized terms, and which terms describe individual subjects.
2
Specify the coefficient distributions.
For example, assign \(u\sim N(0,\tau^2 I)\) to shared penalized coefficients and \(b_i\sim N(0,D)\) to subject-specific coefficients.
3
Check the penalty and covariance match.
The random-effect distribution must induce the intended quadratic penalty; the unpenalized spline directions need separate treatment.

Worked Representations

Worked Example: Fixed Curvature With Subject-Specific Intercept and Slope

Suppose a population trajectory is quadratic, and subjects may vary in their starting levels and linear trends:

$$ \eta_i(t)=\beta_0+\beta_1t+\beta_2t^2+b_{0i}+b_{1i}t. $$

Assume, for illustration, that \(\beta_0=10\), \(\beta_1=1\) outcome unit per time unit, \(\beta_2=0.5\) outcome units per squared time unit, and subject \(i\) has \(b_{0i}=2\) outcome units and \(b_{1i}=-0.3\) outcome units per time unit. At \(t=2\), the fixed population component is

$$ 10 + 1(2) + 0.5(2^2) = 10+2+2=14. $$

The subject-specific departure is \(2+(-0.3)(2)=1.4\) outcome units, so the subject’s conditional mean is \(14+1.4=15.4\) outcome units. The quadratic curvature belongs to the fixed population component; this model gives subjects different levels and slopes, but not different quadratic curvature. That limitation is a modeling decision, not a general property of splines.

Worked Example: A Shared Penalized Spline Coefficient

Consider a deliberately small, whitened spline basis with \(f(t)=\beta_0+\beta_1t+u_1h_1(t)+u_2h_2(t)\), where \(h_1(t)=(t-1)_+^2\), \(h_2(t)=(t-2)_+^2\), and \(a_+=\max(a,0)\). Suppose \(\beta_0=5\), \(\beta_1=0.4\), \(u_1=0.3\), and \(u_2=-0.2\). At \(t=2\), \(h_1(2)=1\) and \(h_2(2)=0\), so

$$ f(2)=5+0.4(2)+0.3(1)-0.2(0)=6.1. $$

Assume the Gaussian residual variance is \(\sigma^2=0.25\) and the shared spline coefficients have variance \(\tau^2=0.0625\). The identity-penalty ratio is \(\lambda=\sigma^2/\tau^2=0.25/0.0625=4\). The quadratic penalty contribution at these coefficients is \(4\{0.3^2+(-0.2)^2\}=4(0.09+0.04)=0.52\). The same \(u_1,u_2\) and hence the same \(f(t)\) apply to all subjects. The example illustrates the penalty-to-variance relation; an actual spline’s penalty matrix and basis scaling must be chosen to match the intended spline penalty.

Worked Example: Covariance From Subject-Specific Spline Departures

Let a subject-specific departure be \(q(t)^\top b_i=b_{0i}+t b_{1i}\), with independent random intercept and slope having variances \(1\) outcome-units-squared and \(0.25\) outcome-units-squared per time-unit-squared, respectively. Thus \(D\) is diagonal with entries \(1\) and \(0.25\). At times \(0\) and \(1\), the basis vectors are \(q(0)=(1,0)^\top\) and \(q(1)=(1,1)^\top\). The subject-level variance at time 1 is

$$ \operatorname{Var}\{q(1)^\top b_i\} =q(1)^\top Dq(1)=1+0.25=1.25. $$

The covariance between the subject departures at times 0 and 1 is

$$ \operatorname{Cov}\{q(0)^\top b_i,q(1)^\top b_i\} =q(0)^\top Dq(1)=1. $$

The intercept induces shared covariance across those times; the independent random slope adds variance at time 1. For two different subjects \(i\ne k\), the subject effects are independent under the stated assumptions, so their subject-specific departures have covariance zero. These calculations concern the \(b_i\) component only; any uncertainty or random-effect covariance associated with the shared population spline is a different part of the model.

Choosing Between Spline Components

The main alternatives differ in what is allowed to vary and how that variation is controlled. A fixed spline can estimate a population curve without a random-effect penalty, but a large basis may be unstable. A shared penalized spline regularizes population flexibility. Subject-specific random spline terms instead describe heterogeneity between individuals and require enough repeated information to estimate that heterogeneity credibly.

ComponentWhat varies?Typical roleMain caution
Fixed spline \(B(t)^\top\beta\)Population coefficients are estimated as fixed parametersPopulation mean shape, including fixed curvatureA very flexible unpenalized basis can overfit
Shared penalized spline \(W(t)^\top u\)One set of coefficients describes a shared curveRegularized population-level curvatureDo not interpret \(u\) as a separate deviation for each subject
Subject-specific spline \(q(t)^\top b_i\)Coefficients vary across subjectsHeterogeneity in levels, slopes, or shapeComplex random curves may be weakly identified with sparse observations

These components can be combined, but their bases and constraints must make their roles distinguishable. For example, if the same flexible basis is included both as an unrestricted fixed spline and as a random subject-specific spline, the model may have weakly identified or redundant components. The design of the bases, the covariance restrictions, and the observation schedule all affect whether the separate sources of variation can be learned from the data.

Assumptions, Diagnostics, and Limitations

The Gaussian mixed-model representation assumes the specified mean structure is adequate, the random-effect distributions are appropriate for the intended inference, and the residual model is reasonable. In particular, the identity-penalty derivation assumes Gaussian residuals with common variance and a Gaussian coefficient distribution with the stated covariance. The equality \(\lambda=\sigma^2/\tau^2\) is specific to that scaling and penalty; it is not a universal numerical conversion for every basis or estimation method.

Useful checks include plotting fitted population and subject-level trajectories against the observations, inspecting residual patterns over time, and checking whether estimated random-effect variances approach zero or covariance estimates become unstable. Large systematic residual patterns may indicate an inadequate spline basis or mean structure. Highly variable subject curves supported by only a few measurements may reflect weak identification rather than genuine heterogeneity. Knot placement and boundary behavior also matter: a basis can be poorly informed near the edges of the observed time range.

In a joint model, the longitudinal submodel’s trajectory can contribute to an event submodel, so separating the shared population shape from subject-level departures is consequential. A subject-specific random curve should not be added merely because it is mathematically possible: it changes the modeled heterogeneity and can make estimation more demanding. Nor does a random-effects representation eliminate uncertainty about the trajectory or correct misspecified time structure.

Common Mistake

Pitfall: “The spline coefficients are random effects, so every subject has a different spline curve.” This is wrong when the coefficients are a single shared vector \(u\) used to regularize the population curve. The correction is to inspect the indexing: a coefficient vector \(u\) shared across subjects represents a shared curve, while \(b_i\) indexed by subject represents subject-specific departure. State both the basis and the level of variation when interpreting a fitted model.

Check Your Understanding

Answer each question by identifying the component and showing the relevant calculation where appropriate.

  1. A model contains \(W(t)^\top u\), where the same \(u\) is used for all subjects. Is this term a separate subject-specific deviation for each subject?
  2. For \(\sigma^2=0.36\) and \(\tau^2=0.09\), calculate the identity-penalty ratio \(\lambda\).
  3. In the model \(\eta_i(t)=\beta_0+\beta_1t+\beta_2t^2+b_{0i}\), which component allows subject-specific variation, and does the model allow subjects to have different quadratic curvature?
  4. If \(b_i\) and \(b_k\) are independent for different subjects, what is the covariance between their subject-specific departures under the model assumptions?

Solutions. (1) No. The shared vector \(u\) describes one population-level penalized curve. (2) \(\lambda=\sigma^2/\tau^2=0.36/0.09=4\). (3) The random intercept \(b_{0i}\) allows subject-specific level variation; the common \(\beta_2\) means subjects do not have different quadratic curvature in this model. (4) It is zero, because independent subject effects have zero cross-subject covariance under the stated assumptions.

Clinical Biostats