Tutorials › Multi-Omics Data Integration › Spline Models For Omics Trajectories

Clinical Outcomes: Survival and Longitudinal Data · Tutorial 456 of 597

Spline Models For Omics Trajectories

Build and interpret spline mixed models that capture nonlinear average omics change while allowing individual trajectories to vary.

Advanced 13 min read

What You'll Learn

  • Define spline basis functions and explain how knots allow trajectory slopes or curvature to change.
  • Specify fixed spline effects for population-average omics trajectories and group differences.
  • Add random spline coefficients to represent between-subject trajectory variation.
  • Calculate fixed-effect and subject-specific predictions at specified follow-up times.
  • Check spline fit, knot choice, residual behavior, and assumptions that can undermine interpretation.
  • Compare spline mixed models with linear-time and polynomial alternatives.

Why Model Omics Trajectories With Splines?

An omics measurement can change gradually, sharply, or in different directions over follow-up. A straight-line model imposes one rate of change across the entire time range, which can hide a plateau or a change in slope. A spline represents the time pattern with joined smooth or piecewise-polynomial sections, allowing the data to support a more flexible trajectory without fitting a separate unrelated curve at every visit.

Here, \(Y_{ij}\) denotes an omics measurement for subject \(i\) at visit \(j\), and \(t_{ij}\) is time since baseline, measured in months. Measurements might be a transformed abundance, such as log2 abundance. The model describes change in that measurement over time; it does not by itself describe a survival outcome or establish that a change causes an outcome.

Spline Basis and Mixed-Model Form

Definition: A spline is a piecewise-polynomial function whose pieces meet at specified time points called knots, with continuity conditions imposed at the joins. A spline basis is a set of known functions \(B_1(t),\ldots,B_q(t)\) whose weighted sum represents a spline: \(f(t)=\sum_{r=1}^{q}\beta_r B_r(t)\). The basis is chosen before estimating the coefficients. The fixed spline effects describe the average time pattern, while random spline effects allow subjects to differ from that pattern.

A useful mixed model for one omics measurement is

$$ Y_{ij}=\mathbf{x}_{ij}^{\mathsf T}\boldsymbol{\beta} +\mathbf{B}(t_{ij})^{\mathsf T}\mathbf{b}_i+\varepsilon_{ij}, \qquad \mathbf{B}(t)=(B_1(t),\ldots,B_q(t))^{\mathsf T}. $$

The fixed-effects design \(\mathbf{x}_{ij}\) can include an intercept, baseline covariates, spline basis terms, and interactions between those terms and a group indicator. The random-effects design \(\mathbf{B}(t)\) may use some or all of the same basis functions. A common model uses a flexible fixed spline but only a random intercept and random linear time slope, which is less demanding than giving each subject a random coefficient for every spline term.

For the usual Gaussian linear mixed model, assume \(\mathbf{b}_i\sim N(\mathbf{0},\mathbf{D})\), \(\varepsilon_{ij}\sim N(0,\sigma^2)\), and that random effects and residual errors are independent. Different subjects' random effects and errors are independent; within a subject, residual errors are conditionally independent given that subject's random effects and the covariates. These assumptions imply that repeated measurements are correlated through \(\mathbf{b}_i\). They also provide the likelihood basis for estimation and inference. In addition, the mean and variance structure must be adequate for the intended inference, the selected basis must be capable of representing the trajectory, and observation or dropout must be ignorable conditional on the modeled information for the usual likelihood analysis to apply.

Knot locations and the number of basis functions control flexibility. Too few basis functions can miss real changes; too many can produce an unstable, wiggly fit, especially with sparse visits. Knot placement should respect the observed follow-up range and avoid creating poorly supported sections. Time units matter: coefficients on time terms change if months are replaced by years, although fitted predictions do not when the model is transformed consistently.

Worked Example: A One-Knot Fixed Spline

Suppose a hypothetical study measures log2 abundance over 12 months. A piecewise-linear fixed trajectory with one knot at month 6 is

$$ m(t)=5.2+0.08t-0.05(t-6)_+, \qquad (t-6)_+=\max(t-6,0). $$

At month 3, the hinge term is zero, so \(m(3)=5.2+0.08(3)=5.44\) log2-abundance units. At month 10, the hinge term is \(10-6=4\), giving \(m(10)=5.2+0.08(10)-0.05(4)=5.80\) log2-abundance units.

Before month 6, the slope is \(0.08\) log2-abundance units per month. After month 6, it is \(0.08-0.05=0.03\) units per month. At the knot, both pieces give \(5.2+0.08(6)=5.68\), so the fitted trajectory is continuous, even though its slope changes there. These are model-based population mean predictions, not claims that every subject follows precisely this curve.

Group Differences and Subject-Specific Trajectories

A group comparison can allow both levels and time patterns to differ. For a binary group indicator \(G_i\), where \(G_i=1\) identifies the group of interest, one example is

$$ E(Y_{ij}\mid G_i,t_{ij})= \beta_0+\beta_GG_i+\beta_1t_{ij}+\beta_K(t_{ij}-k)_+ +\gamma_1G_it_{ij}+\gamma_KG_i(t_{ij}-k)_+. $$

The group contrast at time \(t\) is \(\beta_G+\gamma_1t+\gamma_K(t-k)_+\), not just \(\beta_G\). The latter is the contrast at baseline in this parameterization. A group-by-time interaction allows the curves to diverge or converge; the group-by-hinge interaction additionally allows their slope difference to change at the knot.

For an individual, the random-effects term shifts or reshapes the population curve. A subject-specific prediction uses estimates of that subject's random coefficients, often empirical Bayes estimates, along with the fitted fixed effects. These estimates are partially pooled: they are shrunk toward zero rather than being unrestricted separate fits. For a new subject without repeated measurements, the conditional mean random effect is zero, so the population prediction is the natural prediction before subject-specific information is available.

Worked Example: Comparing Group Trajectories

Consider hypothetical log2-abundance measurements with a knot at month 6. Let the fitted fixed coefficients be \(\beta_0=4.8\), \(\beta_G=0.4\), \(\beta_1=0.10\), \(\beta_K=-0.06\), \(\gamma_1=-0.04\), and \(\gamma_K=0.02\). At month 3, the control-group prediction is \(4.8+0.10(3)=5.10\). The group-1 prediction is \(4.8+0.4+0.10(3)-0.04(3)=5.38\). The group-1 minus control contrast is \(5.38-5.10=0.28\) log2-abundance units.

At month 9, the hinge value is \(9-6=3\). The control prediction is \(4.8+0.10(9)-0.06(3)=5.52\). The group-1 prediction is \(4.8+0.4+0.10(9)-0.06(3)-0.04(9)+0.02(3)=5.62\). The contrast is \(5.62-5.52=0.10\) log2-abundance units. Thus, the estimated difference narrows from 0.28 at month 3 to 0.10 at month 9. The group-1 slope is \(0.10-0.04=0.06\) units per month before month 6, and \(0.10-0.06-0.04+0.02=0.02\) units per month after it. The calculations describe fitted associations over time, not causal group effects.

Why the Random Effects Create Correlation

The subject-specific spline term accounts for repeated observations from the same person. Conditional on the random effects, the model treats residual errors as independent; marginally, observations share the same random coefficients and are therefore correlated. If \(\mathbf{Z}(t)\) is the random-effects design vector and the random-effects covariance is \(\mathbf{D}\), then for two different visits of the same subject,

$$ \operatorname{Cov}\{Y_i(t),Y_i(s)\} =\mathbf{Z}(t)^{\mathsf T}\mathbf{D}\mathbf{Z}(s). $$

This follows because the fixed mean contributes no covariance, the independent residuals contribute zero covariance across different visits, and the shared random effects contribute the displayed term. At the same visit, residual variance \(\sigma^2\) is added under the stated model.

For example, consider a random intercept, random linear slope, and random hinge coefficient at month 6. The conditional trajectory is the fixed mean plus \(b_{i0}+b_{i1}t+b_{iK}(t-6)_+\). This allows subject-specific level, linear trend, and post-knot change. The covariance parameters in \(\mathbf{D}\) determine how much these features vary and co-vary across subjects; they are not themselves the average trajectory.

Worked Example: A Subject-Specific Prediction

Use the fixed trajectory from the first example. Suppose a hypothetical subject's estimated random coefficients are \(b_{i0}=0.30\), \(b_{i1}=-0.02\) per month, and \(b_{iK}=-0.03\) per month for the hinge term. At month 3, the random deviation is \(0.30-0.02(3)-0.03(0)=0.24\) log2-abundance units. The subject-specific prediction is \(5.44+0.24=5.68\) units.

At month 10, the random deviation is \(0.30-0.02(10)-0.03(4)=0.30-0.20-0.12=-0.02\) units. The subject-specific prediction is \(5.80-0.02=5.78\) log2-abundance units. The subject's estimated deviation changes over follow-up because the random slope and random hinge coefficient contribute differently at different times. This is a fitted conditional trajectory, not an error-free measurement of the individual's true biological path.

Justification: Why a Hinge Term Makes a Joined Spline

For a one-knot piecewise-linear model \(m(t)=\beta_0+\beta_1t+\beta_K(t-k)_+\), the hinge is zero when \(t\leq k\) and equals \(t-k\) when \(t>k\). Immediately to the left of the knot, the model is \(\beta_0+\beta_1t\); immediately to the right, it is \(\beta_0+\beta_1t+\beta_K(t-k)\). Substituting \(t=k\) into both pieces gives \(\beta_0+\beta_1k\), proving continuity. Differentiating on either side gives slopes \(\beta_1\) and \(\beta_1+\beta_K\), respectively. Thus the hinge changes the slope without creating a jump in the fitted value. More complex spline bases impose additional continuity conditions, including continuity of derivatives for cubic splines.

Fitting, Diagnostics, and Alternatives

After choosing a basis and random-effects structure, estimate the fixed coefficients, covariance matrix, and residual variance using a mixed-model likelihood method. Restricted maximum likelihood is commonly used to estimate variance components when comparing models with the same fixed-effects structure. When comparing different fixed-effects structures, maximum likelihood is generally used for likelihood-based comparisons because restricted likelihoods depend on the fixed-effects design. A likelihood comparison is not a substitute for checking whether the time pattern is plausible and adequately supported by the data.

Inspect the fitted population curve alongside observed measurements, with subjects or visit times visible enough to reveal gaps and influential regions. Examine residuals against fitted values and time for systematic structure, changing spread, or outliers; assess whether the assumed residual distribution is seriously inadequate when inference depends on Gaussian errors. Check whether estimated random effects or their covariance are unstable, whether predictions at the ends of follow-up are supported by observations, and whether conclusions change materially under reasonable knot choices. Sparse data near a knot cannot reliably identify a local change in slope.

A linear-time mixed model is simpler and more precise when a straight-line pattern is adequate, but it cannot represent a bend. A polynomial in time can represent curvature with few terms, but high-degree polynomials may behave erratically near the edges and do not localize a change in slope. Splines offer local flexibility and interpretable knot behavior, at the cost of choices about basis, knots, and random-effects complexity. Smooth additive models can estimate smooth time functions with penalization, but they are a different modeling approach and do not automatically provide the same explicit subject-level random spline structure.

Spline predictions are most reliable within the observed follow-up range; extrapolation beyond it is basis-dependent and can be misleading. A fitted bend is not automatically a biological transition, particularly if the knot was selected after inspecting noisy data. Finally, missing visits or dropout related to unobserved omics values can violate the assumptions supporting ordinary mixed-model likelihood inference. A spline makes the mean trajectory flexible; it does not repair a misspecified observation process or turn repeated observational measurements into causal evidence.

Common Pitfalls

  • Reading a coefficient as the whole trajectory. With time interactions, a group coefficient is generally the contrast at the reference time, not a constant difference at every visit. Calculate the full contrast at the time of interest.
  • Adding many knots because the curve looks irregular. Extra flexibility can fit noise and produce unstable predictions. Check support around each knot and compare a small number of scientifically plausible specifications.
  • Confusing population and subject-specific predictions. A fixed-effects prediction sets random effects to zero; an individual prediction also uses estimated subject-specific random effects. State which is being reported.
  • Interpreting random effects as independent errors at each visit. Shared random coefficients induce within-subject correlation. Ignoring that dependence can make uncertainty estimates misleading.
Key takeaway: Fixed spline effects describe the average nonlinear time pattern, while random spline effects represent subject-to-subject variation around it. Interpret predictions with their time units, group contrast, and population or subject-specific status made explicit.

Check Your Understanding

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

  1. For \(m(t)=3+0.2t-0.1(t-5)_+\), calculate the fitted value and slope at month 8.
  2. In a group-by-time spline model, why is the group coefficient alone generally not the group contrast at month 7?
  3. What component of a random spline model induces correlation between measurements from the same subject at different visits?
  4. Name one diagnostic for a spline mixed model and one limitation of predictions beyond the observed follow-up range.

Solutions. (1) The hinge is \(8-5=3\), so \(m(8)=3+0.2(8)-0.1(3)=4.3\) units. After the knot the slope is \(0.2-0.1=0.1\) units per month. (2) The contrast includes the group coefficient plus the group-by-time and group-by-hinge terms evaluated at month 7; those interaction contributions can change the contrast over time. (3) The shared subject random effects induce covariance, specifically \(\mathbf{Z}(t)^{\mathsf T}\mathbf{D}\mathbf{Z}(s)\) for different visits under the model assumptions. (4) For example, inspect residuals against time for systematic patterns and compare fitted curves across reasonable knot choices. Beyond observed follow-up, predictions depend strongly on the chosen spline basis and may not represent the true trajectory.

Clinical Biostats