Why a Spline’s Boundary Behavior Matters
A flexible curve can follow changes in a relationship across the predictor values represented in the data. But a prediction just beyond the largest observed predictor value is different from one between observed values: the data no longer provide direct information about how the relationship continues. The way a spline is extended at its boundary can therefore have a substantial effect on an extrapolated prediction.
This tutorial compares two common choices. An ordinary cubic spline is often extrapolated by continuing its outermost cubic polynomial piece. A natural cubic spline is commonly extended linearly beyond its boundary knots. These are different shape assumptions, not guarantees about what the true relationship does outside the data range. Even a small distance beyond the observed range can matter when the competing extensions curve differently.
For context, write a regression model as \(Y_i=f(x_i)+\varepsilon_i\), where \(f(x_i)\) is the conditional mean modeled by a spline and \(\varepsilon_i\) is the error for observation \(i\). The usual regression assumptions concern the errors—for example, that their conditional means are zero. Those assumptions do not establish that the shape chosen for \(f(x)\) remains correct beyond the predictor values observed in the data.
Two Common Extension Rules
An ordinary cubic spline is made of cubic polynomial pieces joined at knots under the spline’s smoothness constraints. For extrapolation, a common convention is to extend the final cubic piece to the right of the right boundary knot and the first cubic piece to the left of the left boundary knot. A cubic piece may contain a nonzero squared term or cubed term, so continuing it can produce increasingly rapid changes in slope or curvature.
For a natural cubic spline, the fitted function is linear outside its boundary knots under the standard natural-spline extension convention. Thus, beyond the right boundary knot, its fitted value continues with the slope at that boundary; beyond the left boundary knot, it continues with the slope there. This is a restriction on the fitted curve’s tails, not a finding that the real relationship must be linear outside the data range.
The linear-tail result can be justified directly. On the region beyond a natural spline’s boundary knot, the standard extension has zero second derivative. If \(f''(x)=0\) throughout that region, integrating once shows that \(f'(x)\) is constant; integrating again shows that \(f(x)\) is a straight line.
Here \(a\) and \(c\) are constants determined by matching the spline’s value and slope at the boundary. The zero-curvature tail does not mean that the entire natural spline is linear: within the boundary knots, its pieces may curve. Nor should one assume that extending the last cubic polynomial piece of an ordinary spline gives a natural spline’s tail. These are different extrapolation rules.
Worked Predictions Beyond a Right Boundary
The calculations below compare extension rules for illustrative fitted curves. They do not describe a real study. To keep the comparison focused on the tails, both curves start at the same fitted value and slope at the right boundary. Their behavior is nonetheless different once the predictor moves beyond that boundary.
Worked Example: Comparing Cubic and Linear Tails
Suppose a hypothetical fitted curve has a right boundary at \(x=10\). Let \(u=x-10\) denote the distance beyond that boundary. Assume the ordinary cubic’s outer piece is \(5+2u+0.3u^2+0.04u^3\), while the natural spline’s linear extension is \(5+2u\). The response is measured in hypothetical response units.
At \(x=10\), \(u=0\), so both extensions give a fitted value of \(5\). Their slopes at the boundary also agree: the linear tail has slope \(2\), and the cubic’s derivative with respect to \(u\) is \(2+0.6u+0.12u^2\), which equals \(2\) at \(u=0\).
At \(x=11\), \(u=1\). The ordinary cubic prediction is \(5+2(1)+0.3(1)^2+0.04(1)^3=7.34\) response units. The natural spline prediction is \(5+2(1)=7\) response units.
At \(x=12\), \(u=2\). The ordinary cubic prediction is \(5+2(2)+0.3(2)^2+0.04(2)^3=5+4+1.2+0.32=10.52\) response units. The natural spline prediction is \(5+2(2)=9\) response units.
At \(x=14\), \(u=4\). The ordinary cubic prediction is \(5+2(4)+0.3(4)^2+0.04(4)^3=5+8+4.8+2.56=20.36\) response units. The natural spline prediction is \(5+2(4)=13\) response units. The difference is \(20.36-13=7.36\) response units. Although both curves agreed in value and slope at the boundary, their predictions separate farther beyond it.
This example illustrates a possibility, not a universal direction of difference. An ordinary cubic can bend upward or downward depending on its coefficients; it need not always predict larger values than a natural spline. The important point is that the cubic tail can keep changing slope, while the natural tail keeps its boundary slope. If the ordinary cubic’s higher-order terms are zero, its extension might itself be linear.
Worked Example: Extrapolating to the Left
Suppose the left boundary of a hypothetical predictor range is \(x=0\), and the response is measured in hypothetical response units. The natural spline’s left tail is \(12-1.5x\). Assume the ordinary cubic’s first piece, continued to the left, is \(12-1.5x+0.2x^2-0.05x^3\). Both have boundary value \(12\) and boundary slope \(-1.5\).
For a prediction at \(x=-2\), the natural extension gives \(12-1.5(-2)=12+3=15\) response units.
The ordinary cubic extension gives \(12-1.5(-2)+0.2(-2)^2-0.05(-2)^3\). Substituting the powers, this is \(12+3+0.8+0.4=16.2\) response units.
The extensions differ by \(16.2-15=1.2\) response units at \(x=-2\). As in the right-boundary example, the two fitted curves agree in value and slope at the boundary but need not agree outside it. The sign and size of the difference depend on the cubic coefficients and the distance from the boundary.
Boundary Predictions Need Special Caution
A curve’s apparent adequacy within the observed predictor range does not by itself justify an extrapolation. In the observed range, data can constrain the fitted relationship at many predictor values. Beyond the range, the prediction relies increasingly on the extension rule and the fitted behavior near the boundary. The residuals within the data cannot directly show whether that rule describes the unobserved region.
A natural spline may produce a less rapidly changing tail than an ordinary cubic, but “linear” does not mean “certain,” “more accurate,” or “scientifically correct.” Its tail is still an extrapolation based on a modeling choice. Conversely, an ordinary cubic’s curved tail may be plausible in some applications, but continuing curvature without evidence can yield extreme or implausible predictions. A different functional form or additional data could change the conclusion.
Worked Example: Reporting a Prediction With Its Boundary Context
Suppose hypothetical measurements were collected for a predictor \(x\) between 2 and 10 units. A fitted ordinary cubic predicts a mean response of \(14.78\) units at \(x=13\), while a fitted natural cubic spline predicts \(11\) units there. Assume, for illustration, that both models give the same value and slope at \(x=10\), and that the ordinary cubic tail beyond 10 has the form \(5+2u+0.3u^2+0.04u^3\), where \(u=x-10\). Its natural-spline comparator has the linear tail \(5+2u\).
At the requested predictor value, \(u=13-10=3\). The ordinary cubic prediction is \(5+2(3)+0.3(3)^2+0.04(3)^3=5+6+2.7+1.08=14.78\) response units. The natural spline prediction is \(5+2(3)=11\) response units. The difference is \(14.78-11=3.78\) response units.
Because \(13\) is above the observed maximum of \(10\), both values are extrapolations. A careful report would identify the predicted response, the predictor value and units, and the model’s extension rule. It would note that the models disagree by \(3.78\) response units at this extrapolated value and that the data range does not directly verify either tail. It would not present \(14.78\) as a measured outcome or as a prediction supported by observations up to \(x=13\).
How to Assess an Extrapolated Spline Value
Before interpreting a boundary prediction, determine where the observed predictor values end, where the spline’s boundary knots lie, and how the software extends the fitted curve outside those knots. These details matter because the same fitted values within the data range can be associated with different tail rules. In particular, software may implement prediction outside a fitted range differently, so the model name alone may not tell you the exact extrapolation convention.
Compare the requested predictor value with the observed minimum and maximum, and with the boundary knots. State whether it is interpolation or extrapolation.
Check whether the ordinary spline continues an outer cubic piece, the natural spline uses a linear tail, or the fitting procedure uses another convention.
If the extrapolation matters, compare predictions under reasonable extension choices and describe any material disagreement in response units.
Report the prediction as model-based and beyond the observed range. Do not treat fit within the data range as direct evidence for the tail.
Common Mistake
A common mistake is to say, “The natural spline is linear beyond the boundary, so its extrapolated prediction is reliable,” or, “The ordinary cubic fit the observed data well, so its tail must also be good.” Both arguments confuse a model’s mathematical extension with empirical support. A natural spline’s linear tail follows from its extension rule; a continued ordinary cubic follows from a different rule. Neither rule, by itself, establishes that the unobserved relationship follows that shape.
Check Your Understanding
Answer each question using the definitions and extension rules in this tutorial.
- A model is fitted using predictor values from 4 to 18. Is a prediction at \(x=15\) interpolation or extrapolation? What about a prediction at \(x=20\)?
- Why does a natural cubic spline have a linear tail under the standard extension convention? State what the zero second derivative implies.
- An ordinary cubic and a natural cubic agree in value and slope at the right boundary. Must their predictions remain equal beyond it? Explain.
- Give one reason that a good fit within the observed predictor range does not establish that an extrapolated prediction is accurate.
- What boundary and implementation details should be checked before interpreting a spline prediction beyond the observed range?