- Introduced by
- Spline regression literature; P-splines by Eilers & Marx
- Year
- 1996
- Type
- Piecewise-polynomial nonparametric regression
What does it do?
Regression splines model a nonlinear relationship by fitting piecewise polynomials that join smoothly at a set of points called knots.
Cubic and natural splines are common choices, and smoothing and penalized splines add a roughness penalty that balances fit against smoothness. Splines are a widely used flexible tool for univariate nonlinear regression and serve as smooth terms in generalized additive models.
The intuition behind the method
Trying to fit a single high-degree polynomial to curved data is notoriously unstable — it wiggles wildly, especially at the edges. Splines solve this by breaking the range into segments at knots and fitting a low-degree polynomial (usually cubic) within each, while forcing the pieces to meet seamlessly — same value, slope, and curvature at every knot. The result is a smooth curve that can follow local structure without the global instability of high-degree polynomials. A smoothing spline takes this further by putting a knot at every data point and instead controlling flexibility through a penalty on curvature.
History
Eilers and Marx (1996) proposed penalized B-splines: a relatively large number of knots combined with a difference penalty on the coefficients of adjacent B-splines. They also showed connections to the familiar spline penalty on the integral of the squared second derivative. Some software documentation cites the P-spline work with a different year, so check the original paper when citing. Splines are treated in Hastie, Tibshirani and Friedman (2009) as a standard smooth term in nonparametric regression, including natural cubic and smoothing splines.
When to use it
Use regression or smoothing splines when you need to model a smooth, nonlinear relationship between a response and a single continuous predictor, either as a standalone curve or as the smooth terms inside a generalized additive model. They can also be used for nonlinear trends in time series, though serial correlation must then be handled. Penalized splines avoid manual knot placement, because the fit is governed by one smoothing parameter that can be chosen automatically. Typical assumptions to check (general statistical assumptions): independent observations (or an explicit model for dependence), roughly constant error variance (or a weighted fit), and a smooth underlying function over the observed range. Splines extrapolate poorly beyond the observed data, and natural splines only partly mitigate this at the edges. For multivariate nonlinear surfaces with interactions, tensor-product splines or other methods are needed. When the relationship is plausibly linear, ordinary regression is simpler.
Limitations and considerations
- Extrapolate unreliably beyond the range of the observed data.
- Unpenalized splines are sensitive to the number and placement of knots.
- Primarily univariate; multivariate surfaces with interactions need tensor products or other methods.
- Choice of basis, degree, and smoothing parameter all affect the result.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Flexible, smooth fits without the instability of high-degree global polynomials.
- Reduce to linear regression on a basis, so estimation and inference are standard.
- Smoothing splines avoid manual knot selection via a single penalty parameter.
- Form the interpretable smooth components of generalized additive models.
Applications
- Flexible univariate curve fitting in the sciences and engineering.
- Smooth terms within generalized additive models for nonlinear effects.
- Nonparametric logistic regression, density estimation and scatterplot smoothing (examples in Eilers and Marx, 1996).
- Smoothing noisy signals and calibration curves.
How it works
How it works
The fitted function is a linear combination of spline basis functions defined relative to a chosen set of knots. Working with a numerically stable basis, such as B-splines or natural-spline basis functions, turns the problem into an ordinary linear regression on the transformed predictors, so standard least-squares machinery applies.
Formula
f(x) = \sum_{k=1}^{K} \beta_k\, B_k(x),\ \text{with knots } \xi_1 < \cdots < \xi_mFor a cubic spline, the pieces are joined so that the function and its first and second derivatives are continuous at each interior knot. This continuity makes the curve smooth rather than kinked, while still allowing its shape to change from segment to segment. A natural spline adds boundary constraints (linear beyond the outer knots) to limit erratic behaviour at the edges.
Formula
f,\ f',\ f''\ \text{continuous at each interior knot (cubic spline)}A smoothing spline minimizes the residual sum of squares plus λ times the integrated squared second derivative, which penalizes total curvature. The minimizer is a natural cubic spline with knots at the data points, so the main modelling choice becomes the single smoothing parameter λ rather than knot placement. P-splines (Eilers and Marx) pursue the same aim differently: they use a relatively large number of B-spline knots and penalize differences between coefficients of adjacent B-splines, a penalty shown to be connected to the integrated squared second derivative.
Formula
\min_{f} \sum_i \big(y_i - f(x_i)\big)^2 + \lambda \int f''(x)^2\,dxWith a fixed basis and penalty, the coefficients have a closed-form penalized least-squares solution, β̂ = (BᵀB + λP)⁻¹Bᵀy. Here B is the basis matrix and P is the penalty matrix. For a P-spline, P = DᵀD, where D is a difference matrix acting on adjacent B-spline coefficients (second-order differences are common). For a smoothing spline in a basis representation, P is the matrix of integrals of products of second derivatives of the basis functions. With λ = 0 this reduces to ordinary least squares on the basis, where the number and position of knots control flexibility. The parameter λ governs the trade-off between bias and variance and is typically selected by cross-validation, generalized cross-validation, or restricted maximum likelihood. Reading the result: for a penalized fit, report the chosen smoothing parameter and the effective degrees of freedom (edf), which summarizes how flexible the curve is. Inspect the curve with pointwise confidence bands and check residual plots. A very wiggly curve with high edf suggests overfitting; a nearly straight curve with edf near 1 suggests heavy smoothing, so confirm that it is not hiding real structure.
Formula
\hat\beta = (B^\top B + \lambda P)^{-1} B^\top yCommon pitfalls
- Placing too many knots, or choosing too small a penalty, produces an overfit, wiggly curve.
- Relying on ordinary cubic splines near the boundaries, where their behaviour can be unstable; natural splines are the usual remedy.
- Extrapolating the fitted curve outside the data range.
- Selecting the smoothing parameter by eye instead of by cross-validation or an equivalent criterion.
- Ignoring correlated errors or strongly non-constant variance, which can make the selected smoothness and confidence bands unreliable.
- Not reporting the smoothing parameter or effective degrees of freedom, which makes the fit hard to interpret or reproduce.
Frequently asked questions
What is a knot in a spline?
A knot is a point along the predictor's range where one polynomial piece ends and the next begins. The pieces are constrained to join smoothly there. More knots allow more flexibility; their number and placement (or, for smoothing splines, the penalty) control how wiggly the fitted curve can be.
What is the difference between a regression spline and a smoothing spline?
A regression spline uses a modest number of chosen knots and is fit by ordinary least squares on the spline basis. A smoothing spline places a knot at every data point and controls flexibility through a roughness penalty with parameter λ, so you tune one penalty instead of selecting knots.
Why use a natural cubic spline?
Ordinary cubic splines can behave erratically near the boundaries where data are sparse. A natural cubic spline adds constraints that force the function to be linear beyond the outermost knots, reducing wild boundary behaviour and the variance of the fit at the edges.
Related methods
Sources
Eilers, P. H. C., & Marx, B. D. (1996). Flexible smoothing with B-splines and penalties. Statistical Science, 11(2), 89–121.
Open DOI referenceHastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed.). Springer.
ISBN: 978-0-387-84857-0