Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Penalized Splines

A curve can fit every observed value and still oscillate wildly between observations. Penalized splines discourage that behavior by charging for curvature, rather than merely counting basis coefficients.

Measuring roughness

For a sufficiently regular function, define

J(f)=∫ab{f′′(u)}2 du.J(f)=\int_a^b\{f''(u)\}^2\,du.

Squaring prevents positive and negative curvature from cancelling. Integrating accumulates bending over the interval. A straight line has f′′=0f''=0 and pays no penalty, regardless of its intercept or slope.

A smoothing spline minimizes

∑i=1n{yi−f(xi)}2+λJ(f).\sum_{i=1}^{n}\{y_i−f(x_i)\}^2+\lambda J(f).

For distinct ordered inputs and a positive smoothing parameter, the standard unrestricted boundary formulation has a natural cubic spline solution with knots at the observed inputs. A penalized regression spline instead begins with a chosen finite basis, often using fewer knots. Both use the same fit versus roughness idea, but their available function spaces need not coincide.

Why the natural cubic spline is enough

Fix the fitted values of any competing function ff at the observations. Let gg be the natural cubic spline interpolating those same values and write h=f−gh=f−g. Then h(xi)=0h(x_i)=0.

Expanding the penalty gives

J(f)=J(g)+2∫abg′′(u)h′′(u) du+J(h).J(f)=J(g)+2\int_a^b g''(u)h''(u)\,du+J(h).

Integration by parts on each knot interval makes the cross term zero. Natural boundary conditions remove the outer boundary terms; continuity and h(xi)=0h(x_i)=0 remove the remaining knot terms. Consequently J(f)≥J(g)J(f)\geq J(g).

Replacing ff by gg leaves the residual sum of squares unchanged and cannot increase roughness. This is why searching over natural cubic splines loses nothing in the smoothing problem.

Turning curvature into a matrix

Write f(x)=b(x)⊤βf(x)=b(x)^\top\beta. Since f′′(x)=b′′(x)⊤βf''(x)=b''(x)^\top\beta,

J(f)=β⊤Sβ,Sjk=∫abbj′′(u)bk′′(u) du.J(f)=\beta^\top S\beta,\qquad S_{jk}=\int_a^b b_j''(u)b_k''(u)\,du.

The matrix SS is symmetric and positive semidefinite. Its entries can be computed interval by interval because the derivatives are polynomials within each knot interval.

The coefficient objective becomes

L(β)=∥y−Bβ∥2+λβ⊤Sβ.L(\beta)=\lVert y−B\beta\rVert^2+\lambda\beta^\top S\beta.

Differentiation gives

−2B⊤(y−Bβ)+2λSβ=0,−2B^\top(y−B\beta)+2\lambda S\beta=0,

and hence

β^λ=(B⊤B+λS)−1B⊤y.\widehat\beta_\lambda=(B^\top B+\lambda S)^{−1}B^\top y.

This inverse exists when no nonzero coefficient direction is invisible both to the data and to the penalty. Equivalently, null⁡(B)∩null⁡(S)={0}\operatorname{null}(B)\cap\operatorname{null}(S)=\{0\}. In computation, solve the system rather than explicitly forming an inverse.

What a large penalty leaves behind

For a full spline basis containing all linear functions, the nullspace of SS has dimension two. It represents the intercept and slope. Larger λ\lambda suppresses departures from a straight line, not the line itself.

If the data identify both unpenalized directions, the limit as λ→∞\lambda\to\infty is the least squares straight line. It is not generally the zero function. At small λ\lambda, the fit approaches the unpenalized fit available in the chosen spline basis; that fit interpolates only if the basis and design allow it.

Three spline fits to the same simulated observations with increasing curvature penalties.

Illustrative simulated data with one fixed cubic basis. Increasing the curvature penalty moves the estimate toward a straight line. The observations and knots are identical in all three panels.

Separating penalized and unpenalized directions

Let S=URDUR⊤S=U_RDU_R^\top, where DD contains the positive eigenvalues, and let UFU_F span its nullspace. Write

β=URθR+UFθF.\beta=U_R\theta_R+U_F\theta_F.

Then

Bβ=BURθR+BUFθF,β⊤Sβ=θR⊤DθR.B\beta=BU_R\theta_R+BU_F\theta_F,\qquad\beta^\top S\beta=\theta_R^\top D\theta_R.

The FF component is a free linear trend. The RR component describes curvature and is penalized. Setting γ=D1/2θR\gamma=D^{1/2}\theta_R turns its penalty into ∥γ∥2\lVert\gamma\rVert^2, with transformed design BURD−1/2BU_RD^{−1/2}. This makes the connection to ordinary ridge explicit.