Why impose natural boundary constraints?
A cubic regression spline can bend flexibly between its knots. But a cubic polynomial continued toward the edge of the data range can behave in ways that are driven more by its mathematical form than by the observations. A natural cubic spline addresses the boundary by requiring zero second derivative at each boundary knot. This tutorial develops that definition and shows exactly how the two constraints reduce the number of free basis functions.
Let \(a\) and \(b\) be the boundary knots, with \(a<b\), and let \(\xi_1,\ldots,\xi_K\) be distinct interior knots satisfying \(a<\xi_1<\cdots<\xi_K<b\). We work with cubic splines that are twice continuously differentiable at the interior knots, as in the earlier material on cubic regression splines and knot continuity.
For regression, the mean response is represented as \(E(Y_i\mid x_i)=f(x_i)\). The spline construction concerns the form of \(f\), rather than a particular error distribution. When fitting by ordinary least squares, the usual regression model writes \(Y_i=f(x_i)+\varepsilon_i\); for classical standard errors, one commonly assumes independent errors with mean zero and constant variance, and normal errors when exact small-sample \(t\)- or \(F\)-inference is required. None of those error assumptions changes the boundary constraints or the basis derivation.
Starting from the cubic truncated-power basis
With \(K\) interior knots, a general cubic spline can be written in the truncated-power basis. Define \((u)_+=\max(u,0)\), so that \((x-\xi_j)_+^3\) is zero to the left of knot \(\xi_j\) and equals \((x-\xi_j)^3\) to its right. The general representation is
There are \(K+4\) coefficients: four polynomial coefficients and one coefficient for each interior knot. Its second derivative is
At the lower boundary \(a\), every interior-knot term is zero because \(a<\xi_j\). At the upper boundary \(b\), each truncated linear term is \(b-\xi_j\). Therefore the natural constraints become two linear equations in the coefficients:
How the two constraints reduce the basis
The first equation gives \(\beta_2=-3a\beta_3\). Substituting this into the second equation and solving for \(\beta_3\) gives
Because \(b-a\ne 0\), these equations determine \(\beta_2\) and \(\beta_3\) from the knot coefficients. The coefficients \(\beta_0,\beta_1\) and \(\gamma_1,\ldots,\gamma_K\) remain free. Thus the natural spline has \(K+2\) free coefficients, two fewer than the unrestricted cubic spline.
Substituting the solved coefficient into the original function gives a reduced basis representation. For each interior knot, define
Then every natural cubic spline with these knots can be written as
The reduced set of basis functions is therefore \(1,x,g_1(x),\ldots,g_K(x)\). The two ordinary polynomial columns \(x^2\) and \(x^3\) no longer appear as independent columns: their coefficients have been determined by the boundary constraints. The resulting basis has \(K+2\) columns, matching the coefficient count.
Worked constructions
Worked Example: Counting the Natural Spline Coefficients
Suppose a cubic spline has four distinct interior knots between its boundary knots. How many coefficients does the unrestricted spline have, and how many remain after imposing the natural constraints?
The truncated-power representation contains the four polynomial terms \(1,x,x^2,x^3\) and four truncated-power terms, one for each interior knot. Thus it has \(4+4=8\) free coefficients.
The natural conditions \(f''(a)=0\) and \(f''(b)=0\) are two independent linear constraints. They reduce the number of free coefficients by two:
Equivalently, with \(K=4\), the reduced basis has \(K+2=6\) functions: an intercept, \(x\), and four natural-spline basis functions. This count is about the function space; an observed data set must also contain enough distinct predictor values for all six coefficients to be estimable.
Worked Example: Deriving a Basis with Two Interior Knots
Let the boundary knots be \(a=0\) and \(b=10\), and let the interior knots be \(\xi_1=3\) and \(\xi_2=7\). Begin with
The second derivative at \(x=0\) is \(2\beta_2\), since both truncated terms are zero there. The first natural constraint therefore gives \(\beta_2=0\). At \(x=10\), the second derivative is
Using \(\beta_2=0\), this becomes \(60\beta_3+42\gamma_1+18\gamma_2=0\), so
The reduced basis functions are consequently
To verify the boundary constraints directly, \(g_1''(0)=0\) and \(g_2''(0)=0\), because the truncated terms and the second derivative of \(x^3\) are both zero at 0. At 10, the second derivatives are
Thus \(f(x)=\beta_0+\beta_1x+\gamma_1g_1(x)+\gamma_2g_2(x)\) satisfies both natural constraints for any choices of its four free coefficients.
Worked Example: Evaluating a Natural Spline Basis Function
Use the boundaries and knots from the previous example, and choose \(\beta_0=2\), \(\beta_1=0.5\), \(\gamma_1=0.02\), and \(\gamma_2=-0.01\). The resulting function is
At \(x=5\), the first truncated term is \((5-3)^3=8\), and the second is zero because \(5<7\). Hence
Substitution gives the fitted function value
The same coefficients in the unrestricted representation would be \(\beta_2=0\) and \(\beta_3=-0.7(0.02)-0.3(-0.01)=-0.011\). Checking at the upper boundary gives
At the lower boundary, \(f''(0)=2\beta_2=0\). Both constraints hold, and \(3.285\) is the function value at \(x=5\), in the response units used to define the coefficients.
Using the basis in regression
Once the knots and boundary interval have been chosen, the reduced basis can be evaluated at each observed predictor value. The regression design matrix has one column for the constant function, one for \(x\), and one for each \(g_j(x)\). Ordinary least squares estimates the \(K+2\) coefficients in that representation, provided the design matrix has full column rank. This is a standard linear regression in its coefficients even though the fitted mean can be curved as a function of \(x\).
The boundary knots are part of the specification, not merely bookkeeping. The constraints apply at those chosen values \(a\) and \(b\); changing them changes the basis functions and the spline space. In practice they are commonly set at the ends of the predictor range being modeled. The interior knots control where the cubic pieces join, while the natural constraints reduce the degrees of freedom available for the curve.
Common mistake
A frequent error is to read “natural boundary condition” as \(f(a)=f(b)=0\), or to force the fitted curve through specified endpoint responses. Those are constraints on function values, not on curvature. The natural cubic spline conditions are specifically \(f''(a)=0\) and \(f''(b)=0\). In the truncated-power derivation, it is the second-derivative equations that determine \(\beta_2\) and \(\beta_3\); \(\beta_0\) and \(\beta_1\) remain free to be estimated from the data.
Another mistake is to subtract two coefficients from the model without showing why. The reduction is justified because the two boundary equations are independent when \(a<b\), and the derivation explicitly solves them. Counting alone is not a substitute for applying the constraints to the chosen spline representation.
Check Your Understanding
Use the definition and basis derivation to answer these questions.
- A cubic spline has six distinct interior knots. How many free coefficients does its unrestricted truncated-power representation have, and how many remain after the natural constraints?
- In the truncated-power basis, why do the interior-knot terms make no contribution to \(f''(a)\) when \(a<\xi_j\) for every \(j\)?
- For \(a=1\), \(b=9\), and one interior knot at \(\xi=5\), write the reduced basis function \(g_1(x)\).
- Explain why \(f(a)=f(b)=0\) is not the definition of a natural cubic spline.
- What condition on the regression design matrix is needed to estimate all coefficients uniquely by ordinary least squares?