Tutorials › Joint Modeling of Longitudinal and Time-to-Event Data › Restricted Cubic Splines at Boundary Knots

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

Restricted Cubic Splines at Boundary Knots

See how restricted cubic splines retain flexible curvature within the boundary knots while forcing linear extrapolation outside them.

Advanced 12 min read

What You'll Learn

  • Define a restricted cubic spline using boundary and interior knots.
  • Construct its nonlinear basis functions and identify their units.
  • Verify why the basis yields linear tails outside the boundary knots.
  • Calculate and interpret hypothetical population and subject-specific trajectory predictions.
  • Diagnose when boundary restrictions or extrapolation may be implausible.
  • Compare restricted cubic splines with alternative trajectory bases.

Why Restrict a Cubic Spline?

Longitudinal biomarkers may change at different rates over follow-up: a trajectory can rise quickly, flatten, or turn downward. A single straight line may miss this pattern, while an unrestricted cubic polynomial can bend sharply, especially beyond the times represented in the data. Restricted cubic splines offer a compromise: they allow smooth curvature over the observed range and require the trajectory to be linear outside designated boundary knots.

That restriction matters in a joint model because the longitudinal submodel represents an underlying biomarker trajectory, not just the values recorded at visits. Predictions beyond the observation window can affect interpretation of the latent trajectory and any event-model quantity that uses it. A linear tail is a modeling constraint, not evidence that the biomarker truly continues linearly after follow-up.

Definition: A restricted cubic spline is a piecewise cubic function that is twice continuously differentiable at its knots and is constrained to be linear below the left boundary knot and above the right boundary knot. The boundary knots delimit the range in which the function is allowed to curve. Knots strictly between them are interior knots.

A Basis With Linear Tails

Let the ordered knots be \(\kappa_1<\kappa_2<\cdots<\kappa_K\), with \(K\geq 3\). The boundary knots are \(\kappa_1\) and \(\kappa_K\); the other knots are interior knots. Define the positive-part cube by \((u)_+^3=\max(u,0)^3\). One common restricted cubic spline basis is

$$ D_j(t)=\frac{(t-\kappa_j)_+^3-(t-\kappa_K)_+^3}{\kappa_K-\kappa_j}, \qquad j=1,\ldots,K-1, $$

and

$$ R_j(t)=D_j(t)-D_{K-1}(t), \qquad j=1,\ldots,K-2. $$

The resulting trajectory can be written as

$$ f(t)=\beta_0+\beta_1t+\sum_{j=1}^{K-2}\beta_{j+1}R_j(t). $$

There are \(K\) coefficients: an intercept, a linear term, and \(K-2\) nonlinear terms. Each \(R_j(t)\) has units of time squared, because a cubed time difference is divided by a time difference. Thus its coefficient has units of biomarker per time squared, so every term in \(f(t)\) has biomarker units.

In a longitudinal submodel, \(f(t)\) can serve as a population mean trajectory. A subject-specific latent trajectory can also include random coefficients on the same basis. In either case, the restriction concerns the shape: outside the boundary knots the spline contribution is linear in time.

Worked Example: Calculating the Basis at an Interior Time

Suppose time is measured in months and the knots are \(0,2,4,6\), so \(K=4\), with boundary knots 0 and 6. Calculate both nonlinear basis functions at month 5.

Here \(D_1(t)\), \(D_2(t)\), and \(D_3(t)\) use knots 0, 2, and 4, respectively, as their first knot, with 6 as the right boundary knot. At \(t=5\), the truncated term \((5-6)_+^3\) is zero. Therefore,

$$ D_1(5)=\frac{5^3}{6}=\frac{125}{6}=20.8333,\quad D_2(5)=\frac{3^3}{4}=\frac{27}{4}=6.7500,\quad D_3(5)=\frac{1^3}{2}=0.5000. $$

Since \(K-2=2\), the two restricted basis functions are

$$ R_1(5)=D_1(5)-D_3(5)=20.8333-0.5000=20.3333, $$
$$ R_2(5)=D_2(5)-D_3(5)=6.7500-0.5000=6.2500. $$

These are basis values, not biomarker measurements. Multiplying them by their corresponding coefficients and adding the intercept and linear term gives the modeled trajectory at month 5.

Why the Tails Are Linear

The linear-tail property follows directly from the basis. If \(t\leq\kappa_1\), every positive-part term in every \(D_j(t)\) is zero. Consequently, every \(R_j(t)=0\), and \(f(t)=\beta_0+\beta_1t\) on the left tail.

For \(t\geq\kappa_K\), expand the two cubes in \(D_j(t)\). For \(j=1,\ldots,K-1\),

$$ D_j(t)=3t^2-3(\kappa_j+\kappa_K)t+ \kappa_j^2+\kappa_j\kappa_K+\kappa_K^2. $$

The \(3t^2\) term is identical for every \(j\). Subtracting \(D_{K-1}(t)\) therefore cancels the quadratic terms and leaves a linear function:

$$ R_j(t)=3(\kappa_{K-1}-\kappa_j)t+ \left(\kappa_j^2+\kappa_j\kappa_K-\kappa_{K-1}^2-\kappa_{K-1}\kappa_K\right), \qquad t\geq\kappa_K. $$

Thus the full trajectory on the right tail is linear. This establishes the main algebraic result: the restriction is built into the choice of basis, rather than imposed later by trimming a fitted curve.

The basis is also smooth at the knots. Each positive-part cube and its first two derivatives agree from the left and right at its knot: the function, first derivative, and second derivative are all zero there. Sums and differences of these terms preserve that continuity. The spline therefore has no jumps in its value, slope, or curvature at a knot.

Worked Example: Predicting Along the Right Tail

Continue with knots \(0,2,4,6\). Suppose a hypothetical population trajectory, with time in months and biomarker level in units, is

$$ f(t)=10+0.40t-0.020R_1(t)+0.030R_2(t). $$

For \(t\geq6\), the basis functions reduce to \(R_1(t)=12t-40\) and \(R_2(t)=6t-24\). At month 7, these are \(R_1(7)=84-40=44\) and \(R_2(7)=42-24=18\). Substituting gives

$$ f(7)=10+0.40(7)-0.020(44)+0.030(18) =10+2.80-0.88+0.54=12.46. $$

The right-tail slope is the coefficient of \(t\) after substituting the linear basis expressions:

$$ 0.40-0.020(12)+0.030(6)=0.340 \quad\text{biomarker units per month}. $$

For example, the month-8 prediction is \(12.46+0.340=12.80\) units. This is the model’s linear extrapolation, not a claim that a biomarker measured after month 6 would necessarily increase at that rate.

Use in a Joint Model and Interpretation

A spline can specify the time-dependent mean in a longitudinal submodel. For example, a Gaussian measurement model might have \(Y_{ij}=m_i(t_{ij})+\epsilon_{ij}\), where \(Y_{ij}\) is the measurement for subject \(i\) at visit \(j\), \(m_i(t)\) is that subject’s latent trajectory, and \(\epsilon_{ij}\) is measurement error. A spline basis can be used in \(m_i(t)\) to allow a nonconstant rate of change. The observation model and any assumptions about random effects or measurement errors still need to be specified separately; the spline basis alone does not supply them.

If the subject-specific trajectory has random spline coefficients, then its tail remains linear conditional on those coefficients. The subject-specific slope may differ from the population slope. In a joint model, any association between a latent trajectory and event risk is interpreted through the specified event submodel; a linear-tail restriction does not itself establish an event association or a causal effect.

Worked Example: A Subject-Specific Tail Slope

Use the same hypothetical population coefficients as above. Suppose a subject has random effects \(b_{i0}=0.20\), \(b_{i1}=0.10\), \(b_{i1}^{*}=0.005\), and \(b_{i2}^{*}=-0.010\), so that the subject-specific trajectory is

$$ m_i(t)=(10+b_{i0})+(0.40+b_{i1})t+ (-0.020+b_{i1}^{*})R_1(t)+(0.030+b_{i2}^{*})R_2(t). $$

For this subject, the coefficients are \(10.20\), \(0.50\), \(-0.015\), and \(0.020\). The subject-specific right-tail slope is

$$ 0.50+12(-0.015)+6(0.020)=0.50-0.18+0.12 =0.440 \quad\text{biomarker units per month}. $$

At month 7, the basis values are 44 and 18, so

$$ m_i(7)=10.20+0.50(7)-0.015(44)+0.020(18) =10.20+3.50-0.66+0.36=13.40. $$

The subject-specific tail is still linear, but its slope is 0.440 units per month rather than the population slope of 0.340 units per month. Whether such subject-specific slopes are estimated reliably depends on the data and the model’s assumptions, not just on the spline construction.

Choosing and Checking the Boundary Restriction

The restriction is useful when a stable, simple extrapolation is preferable to an unconstrained cubic tail. It does not guarantee that the extrapolation is accurate. Beyond the boundary knot, the fitted trajectory cannot bend to reflect a genuine plateau, acceleration, or reversal. The location of the boundary knots therefore encodes a substantive modeling choice: it determines where flexibility ends and linear behavior begins.

Check the fitted trajectory and its first derivative across the observed follow-up range, especially near the boundary knots. Look for abrupt-looking changes in slope, implausible curvature inside the knots, or tail slopes that yield unrealistic predictions when carried beyond the data. A smooth curve can still fit poorly, and a plausible in-range curve can still have a biologically implausible extrapolation. Sparse observations near a boundary also make it difficult to assess how the fitted curve behaves there.

Restricted cubic splines differ from ordinary cubic polynomial regression, which uses a global polynomial and may curve increasingly at extremes. They also differ from an unrestricted piecewise cubic spline, whose tail need not be linear unless boundary constraints are imposed. B-spline bases are another way to represent spline functions; basis choice changes the coordinates used for the function, while restrictions determine the permitted shape. Penalized splines address the balance between fit and smoothness through a penalty; they are a distinct modeling approach, not a consequence of linear-tail restrictions.

Common pitfall: “The restricted cubic spline is linear after the last boundary knot, so its long-term predictions are trustworthy.” The first clause describes the mathematical constraint; it does not justify the extrapolation scientifically. Report the boundary knots and treat predictions beyond them as model-dependent, especially when follow-up data do not support checking the tail.

The boundary restriction can be valuable because it prevents the spline’s cubic components from producing arbitrary curvature indefinitely. Its limitation is equally important: it replaces unconstrained tail curvature with a particular extrapolation assumption. In a joint model, communicate that assumption alongside the fitted trajectory and avoid presenting the tail as if it were directly observed.

Check Your Understanding

Answer each question, then check the solution shown below it.

  1. For knots \(0,2,4,6\), what are \(R_1(t)\) and \(R_2(t)\) at \(t=-1\), and what does the trajectory reduce to there?

    Solution: Since \(t\leq0=\kappa_1\), all positive-part terms are zero. Thus \(R_1(-1)=R_2(-1)=0\), and \(f(-1)=\beta_0-\beta_1\).

  2. Why do the quadratic terms disappear from each \(R_j(t)\) when \(t\geq\kappa_K\)?

    Solution: Each \(D_j(t)\) has the same quadratic term \(3t^2\). The definition \(R_j(t)=D_j(t)-D_{K-1}(t)\) subtracts two such terms, leaving no quadratic term. The result is linear in \(t\).

  3. For the population trajectory in the worked example, what is the predicted value at month 8 using the right-tail slope?

    Solution: The month-7 value is 12.46 units and the tail slope is 0.340 units per month. Therefore, \(f(8)=12.46+0.340(1)=12.80\) units.

  4. Does a linear right tail establish that the biomarker truly changes linearly after the last boundary knot? Explain.

    Solution: No. Linearity beyond the boundary is a restriction of the fitted model. It is an extrapolation assumption, and its scientific accuracy cannot be inferred from the restriction alone.

Clinical Biostats