# Smoothing spline

For a broader coverage related to this topic, see Spline (mathematics).

The smoothing spline is a method of fitting a smooth curve to a set of noisy observations using a spline function.

## Definition

Let ${\displaystyle (x_{i},Y_{i});x_{1} be a sequence of observations, modeled by the relation ${\displaystyle Y_{i}=f(x_{i})}$. The smoothing spline estimate ${\displaystyle {\hat {f}}}$ of the function ${\displaystyle f}$ is defined to be the minimizer (over the class of twice differentiable functions) of[1]

${\displaystyle \sum _{i=1}^{n}(Y_{i}-{\hat {f}}(x_{i}))^{2}+\lambda \int _{x_{1}}^{x_{n}}{\hat {f}}''(x)^{2}\,dx.}$

Remarks:

• ${\displaystyle \lambda \geq 0}$ is a smoothing parameter, controlling the trade-off between fidelity to the data and roughness of the function estimate.
• The integral is evaluated over the range of the ${\displaystyle x_{i}}$.
• As ${\displaystyle \lambda \to 0}$ (no smoothing), the smoothing spline converges to the interpolating spline.
• As ${\displaystyle \lambda \to \infty }$ (infinite smoothing), the roughness penalty becomes paramount and the estimate converges to a linear least squares estimate.
• The roughness penalty based on the second derivative is the most common in modern statistics literature, although the method can easily be adapted to penalties based on other derivatives.
• In early literature, with equally-spaced ${\displaystyle x_{i}}$, second or third-order differences were used in the penalty, rather than derivatives.
• When the sum-of-squares term is replaced by a log-likelihood, the resulting estimate is termed penalized likelihood. The smoothing spline is the special case of penalized likelihood resulting from a Gaussian likelihood.

## Derivation of the smoothing spline

It is useful to think of fitting a smoothing spline in two steps:

1. First, derive the values ${\displaystyle {\hat {f}}(x_{i});i=1,\ldots ,n}$.
2. From these values, derive ${\displaystyle {\hat {f}}(x)}$ for all x.

Now, treat the second step first.

Given the vector ${\displaystyle {\hat {m}}=({\hat {f}}(x_{1}),\ldots ,{\hat {f}}(x_{n}))^{T}}$ of fitted values, the sum-of-squares part of the spline criterion is fixed. It remains only to minimize ${\displaystyle \int {\hat {f}}''(x)^{2}\,dx}$, and the minimizer is a natural cubic spline that interpolates the points ${\displaystyle (x_{i},{\hat {f}}(x_{i}))}$. This interpolating spline is a linear operator, and can be written in the form

${\displaystyle {\hat {f}}(x)=\sum _{i=1}^{n}{\hat {f}}(x_{i})f_{i}(x)}$

where ${\displaystyle f_{i}(x)}$ are a set of spline basis functions. As a result, the roughness penalty has the form

${\displaystyle \int {\hat {f}}''(x)^{2}dx={\hat {m}}^{T}A{\hat {m}}.}$

where the elements of A are ${\displaystyle \int f_{i}''(x)f_{j}''(x)dx}$. The basis functions, and hence the matrix A, depend on the configuration of the predictor variables ${\displaystyle x_{i}}$, but not on the responses ${\displaystyle Y_{i}}$ or ${\displaystyle {\hat {m}}}$.

Now back to the first step. The penalized sum-of-squares can be written as

${\displaystyle \|Y-{\hat {m}}\|^{2}+\lambda {\hat {m}}^{T}A{\hat {m}},}$

where ${\displaystyle Y=(Y_{1},\ldots ,Y_{n})^{T}}$. Minimizing over ${\displaystyle {\hat {m}}}$ gives

${\displaystyle {\hat {m}}=(I+\lambda A)^{-1}Y.}$

## De Boor's approach

De Boor's approach exploits the same idea, of finding a balance between having a smooth curve and being close to the given data.[2]

${\displaystyle p\sum _{i=1}^{n}\left({\frac {Y_{i}-{\hat {f}}\left(x_{i}\right)}{\delta _{i}}}\right)^{2}+\left(1-p\right)\int \left({\hat {f}}^{\left(m\right)}\left(x\right)\right)^{2}\,dx}$

where ${\displaystyle p}$ is a parameter called smooth factor and belongs to the interval ${\displaystyle [0,1]}$, and ${\displaystyle \delta _{i};i=1,\dots ,n}$ are the quantities controlling the extent of smoothing (they represent the weight ${\displaystyle \delta _{i}^{-2}}$ of each point ${\displaystyle Y_{i}}$). In practice, since cubic splines are mostly used, ${\displaystyle m}$ is usually ${\displaystyle 2}$. The solution for ${\displaystyle m=2}$ was proposed by Reinsch in 1967.[3] For ${\displaystyle m=2}$, when ${\displaystyle p}$ approaches ${\displaystyle 1}$, ${\displaystyle {\hat {f}}}$ converges to the "natural" spline interpolant to the given data.[2] As ${\displaystyle p}$ approaches ${\displaystyle 0}$, ${\displaystyle {\hat {f}}}$ converges to a straight line (the smoothest curve). Since finding a suitable value of ${\displaystyle p}$ is a task of trial and error, a redundant constant ${\displaystyle S}$ was introduced for convenience.[3] ${\displaystyle S}$ is used to numerically determine the value of ${\displaystyle p}$ so that the function ${\displaystyle {\hat {f}}}$ meets the following condition:

${\displaystyle \sum _{i=1}^{n}\left({\frac {Y_{i}-{\hat {f}}\left(x_{i}\right)}{\delta _{i}}}\right)^{2}\leq S}$

The algorithm described by de Boor starts with ${\displaystyle p=0}$ and increases ${\displaystyle p}$ until the condition is met.[2] If ${\displaystyle \delta _{i}}$ is an estimation of the standard deviation for ${\displaystyle Y_{i}}$, the constant ${\displaystyle S}$ is recommended to be chosen in the interval ${\displaystyle \left[n-{\sqrt {2n}},n+{\sqrt {2n}}\right]}$. Having ${\displaystyle S=0}$ means the solution is the "natural" spline interpolant.[3] Increasing ${\displaystyle S}$ means we obtain a smoother curve by getting farther from the given data.

## Creating a multidimensional spline

Given the constraint from the definition formula ${\displaystyle x_{1} we can conclude that the algorithm doesn't work for all sets of data. If we plan to use this algorithm for random points in a multidimensional space, to find a solution we need to give, as input to the algorithm, sets of data where these constraints are met. A solution for this is to introduce a parameter so that the input data would be represented as single-valued functions depending on that parameter; after this the smoothing will be performed for each function. In a bidimensional space a solution would be to parametrize ${\displaystyle x}$ and ${\displaystyle y}$ so that they would become ${\displaystyle x(t)}$ and ${\displaystyle y(t)}$ where ${\displaystyle t_{1}. A convenient solution for ${\displaystyle t}$ is the cumulating distance ${\displaystyle t_{i+1}=t_{i}+{\sqrt {(x_{i+1}-x_{i})^{2}+(y_{i+1}-y_{i})^{2}}}}$ where ${\displaystyle t_{1}=0}$.[4][5]

A more detailed analysis on parametrization is done by E.T.Y. Lee.[6]

## Related methods

Smoothing splines are related to, but distinct from:

• Regression splines. In this method, the data is fitted to a set of spline basis functions with a reduced set of knots, typically by least squares. No roughness penalty is used. (See also multivariate adaptive regression splines.)
• Penalized Splines. This combines the reduced knots of regression splines, with the roughness penalty of smoothing splines.[7]
• Elastic maps method for manifold learning. This method combines the least squares penalty for approximation error with the bending and stretching penalty of the approximating manifold and uses the coarse discretization of the optimization problem; see thin plate splines.

## Source code

Source code for spline smoothing can be found in the examples from Carl de Boor's book A Practical Guide to Splines. The examples are in the Fortran programming language. The updated sources are available also on Carl de Boor's official site [1].

## References

1. ^ Hastie, T. J.; Tibshirani, R. J. (1990). Generalized Additive Models. Chapman and Hall. ISBN 0-412-34390-8.
2. ^ a b c De Boor, C. (2001). A Practical Guide to Splines (Revised Edition). Springer. pp. 207–214. ISBN 0-387-90356-9.
3. ^ a b c Reinsch, Christian H. "Smoothing by Spline Functions". Retrieved 18 June 2016.
4. ^ Robert E. Smith Jr., Joseph M Price and Lona M. Howser. "A Smoothing Algorithm Using Cubic Spline Functions" (PDF). Retrieved 31 May 2011.
5. ^ N. Y. Graham. "Smoothing With Periodic Cubic Splines" (PDF). Retrieved 31 May 2011.
6. ^ E.T.Y. Lee. "Choosing nodes in parametric curve interpolation" (PDF). Retrieved 28 June 2011.
7. ^ Ruppert, David; Wand, M. P.; Carroll, R. J. (2003). Semiparametric Regression. Cambridge University Press. ISBN 0-521-78050-0.