Misplaced Pages

Smoothing spline

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Method of smoothing using a spline function

For broader coverage of this topic, see Spline (mathematics).

Smoothing splines are function estimates, f ^ ( x ) {\displaystyle {\hat {f}}(x)} , obtained from a set of noisy observations y i {\displaystyle y_{i}} of the target f ( x i ) {\displaystyle f(x_{i})} , in order to balance a measure of goodness of fit of f ^ ( x i ) {\displaystyle {\hat {f}}(x_{i})} to y i {\displaystyle y_{i}} with a derivative based measure of the smoothness of f ^ ( x ) {\displaystyle {\hat {f}}(x)} . They provide a means for smoothing noisy x i , y i {\displaystyle x_{i},y_{i}} data. The most familiar example is the cubic smoothing spline, but there are many other possibilities, including for the case where x {\displaystyle x} is a vector quantity.

Cubic spline definition

Let { x i , Y i : i = 1 , , n } {\displaystyle \{x_{i},Y_{i}:i=1,\dots ,n\}} be a set of observations, modeled by the relation Y i = f ( x i ) + ϵ i {\displaystyle Y_{i}=f(x_{i})+\epsilon _{i}} where the ϵ i {\displaystyle \epsilon _{i}} are independent, zero mean random variables. The cubic smoothing spline estimate f ^ {\displaystyle {\hat {f}}} of the function f {\displaystyle f} is defined to be the unique minimizer, in the Sobolev space W 2 2 {\displaystyle W_{2}^{2}} on a compact interval, of

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

Remarks:

  • λ 0 {\displaystyle \lambda \geq 0} is a smoothing parameter, controlling the trade-off between fidelity to the data and roughness of the function estimate. This is often estimated by generalized cross-validation, or by restricted marginal likelihood (REML) which exploits the link between spline smoothing and Bayesian estimation (the smoothing penalty can be viewed as being induced by a prior on the f {\displaystyle f} ).
  • The integral is often evaluated over the whole real line although it is also possible to restrict the range to that of x i {\displaystyle x_{i}} .
  • As λ 0 {\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 ordered x i {\displaystyle x_{i}} , second or third-order differences were used in the penalty, rather than derivatives.
  • The penalized sum of squares smoothing objective can be replaced by a penalized likelihood objective in which the sum of squares terms is replaced by another log-likelihood based measure of fidelity to the data. The sum of squares term corresponds to penalized likelihood with a Gaussian assumption on the ϵ i {\displaystyle \epsilon _{i}} .

Derivation of the cubic smoothing spline

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

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

Now, treat the second step first.

Given the vector m ^ = ( f ^ ( x 1 ) , , f ^ ( x n ) ) T {\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 f ^ ( x ) 2 d x {\displaystyle \int {\hat {f}}''(x)^{2}\,dx} , and the minimizer is a natural cubic spline that interpolates the points ( x i , f ^ ( x i ) ) {\displaystyle (x_{i},{\hat {f}}(x_{i}))} . This interpolating spline is a linear operator, and can be written in the form

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

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

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

where the elements of A are f i ( x ) f j ( x ) d x {\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 x i {\displaystyle x_{i}} , but not on the responses Y i {\displaystyle Y_{i}} or m ^ {\displaystyle {\hat {m}}} .

A is an n×n matrix given by A = Δ T W 1 Δ {\displaystyle A=\Delta ^{T}W^{-1}\Delta } .

Δ is an (n-2)×n matrix of second differences with elements:

Δ i i = 1 / h i {\displaystyle \Delta _{ii}=1/h_{i}} , Δ i , i + 1 = 1 / h i 1 / h i + 1 {\displaystyle \Delta _{i,i+1}=-1/h_{i}-1/h_{i+1}} , Δ i , i + 2 = 1 / h i + 1 {\displaystyle \Delta _{i,i+2}=1/h_{i+1}}

W is an (n-2)×(n-2) symmetric tri-diagonal matrix with elements:

W i 1 , i = W i , i 1 = h i / 6 {\displaystyle W_{i-1,i}=W_{i,i-1}=h_{i}/6} , W i i = ( h i + h i + 1 ) / 3 {\displaystyle W_{ii}=(h_{i}+h_{i+1})/3} and h i = ξ i + 1 ξ i {\displaystyle h_{i}=\xi _{i+1}-\xi _{i}} , the distances between successive knots (or x values).

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

{ Y m ^ } T { Y m ^ } + λ m ^ T A m ^ , {\displaystyle \{Y-{\hat {m}}\}^{T}\{Y-{\hat {m}}\}+\lambda {\hat {m}}^{T}A{\hat {m}},}

where Y = ( Y 1 , , Y n ) T {\displaystyle Y=(Y_{1},\ldots ,Y_{n})^{T}} .

Minimizing over m ^ {\displaystyle {\hat {m}}} by differentiating against m ^ {\displaystyle {\hat {m}}} . This results in: 2 { Y m ^ } + 2 λ A m ^ = 0 {\displaystyle -2\{Y-{\hat {m}}\}+2\lambda A{\hat {m}}=0} and m ^ = ( I + λ A ) 1 Y . {\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.

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

i = 1 n ( Y i f ^ ( x i ) δ i ) 2 S {\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 p = 0 {\displaystyle p=0} and increases p {\displaystyle p} until the condition is met. If δ i {\displaystyle \delta _{i}} is an estimation of the standard deviation for Y i {\displaystyle Y_{i}} , the constant S {\displaystyle S} is recommended to be chosen in the interval [ n 2 n , n + 2 n ] {\displaystyle \left} . Having S = 0 {\displaystyle S=0} means the solution is the "natural" spline interpolant. Increasing S {\displaystyle S} means we obtain a smoother curve by getting farther from the given data.

Multidimensional splines

There are two main classes of method for generalizing from smoothing with respect to a scalar x {\displaystyle x} to smoothing with respect to a vector x {\displaystyle x} . The first approach simply generalizes the spline smoothing penalty to the multidimensional setting. For example, if trying to estimate f ( x , z ) {\displaystyle f(x,z)} we might use the Thin plate spline penalty and find the f ^ ( x , z ) {\displaystyle {\hat {f}}(x,z)} minimizing

i = 1 n { y i f ^ ( x i , z i ) } 2 + λ [ ( 2 f ^ x 2 ) 2 + 2 ( 2 f ^ x z ) 2 + ( 2 f ^ z 2 ) 2 ] d x d z . {\displaystyle \sum _{i=1}^{n}\{y_{i}-{\hat {f}}(x_{i},z_{i})\}^{2}+\lambda \int \left{\textrm {d}}x\,{\textrm {d}}z.}

The thin plate spline approach can be generalized to smoothing with respect to more than two dimensions and to other orders of differentiation in the penalty. As the dimension increases there are some restrictions on the smallest order of differential that can be used, but actually Duchon's original paper, gives slightly more complicated penalties that can avoid this restriction.

The thin plate splines are isotropic, meaning that if we rotate the x , z {\displaystyle x,z} co-ordinate system the estimate will not change, but also that we are assuming that the same level of smoothing is appropriate in all directions. This is often considered reasonable when smoothing with respect to spatial location, but in many other cases isotropy is not an appropriate assumption and can lead to sensitivity to apparently arbitrary choices of measurement units. For example, if smoothing with respect to distance and time an isotropic smoother will give different results if distance is measure in metres and time in seconds, to what will occur if we change the units to centimetres and hours.

The second class of generalizations to multi-dimensional smoothing deals directly with this scale invariance issue using tensor product spline constructions. Such splines have smoothing penalties with multiple smoothing parameters, which is the price that must be paid for not assuming that the same degree of smoothness is appropriate in all directions.

Related methods

See also: Curve fitting

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.
  • Thin plate splines and 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.

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 .

References

  1. ^ Green, P. J.; Silverman, B.W. (1994). Nonparametric Regression and Generalized Linear Models: A roughness penalty approach. Chapman and Hall.
  2. Hastie, T. J.; Tibshirani, R. J. (1990). Generalized Additive Models. Chapman and Hall. ISBN 978-0-412-34390-2.
  3. Craven, P.; Wahba, G. (1979). "Smoothing noisy data with spline functions". Numerische Mathematik. 31 (4): 377–403. doi:10.1007/bf01404567.
  4. Kimeldorf, G.S.; Wahba, G. (1970). "A Correspondence between Bayesian Estimation on Stochastic Processes and Smoothing by Splines". The Annals of Mathematical Statistics. 41 (2): 495–502. doi:10.1214/aoms/1177697089.
  5. Whittaker, E.T. (1922). "On a new method of graduation". Proceedings of the Edinburgh Mathematical Society. 41: 63–75.
  6. Rodriguez, German (Spring 2001). "Smoothing and Non-Parametric Regression" (PDF). 2.3.1 Computation. p. 12. Retrieved 28 April 2024.{{cite web}}: CS1 maint: location (link)
  7. ^ De Boor, C. (2001). A Practical Guide to Splines (Revised Edition). Springer. pp. 207–214. ISBN 978-0-387-90356-9.
  8. ^ Reinsch, Christian H (1967). "Smoothing by Spline Functions". Numerische Mathematik. 10 (3): 177–183. doi:10.1007/BF02162161.
  9. J. Duchon, 1976, Splines minimizing rotation invariant semi-norms in Sobolev spaces. pp 85–100, In: Constructive Theory of Functions of Several Variables, Oberwolfach 1976, W. Schempp and K. Zeller, eds., Lecture Notes in Math., Vol. 571, Springer, Berlin, 1977
  10. Wahba, Grace. Spline Models for Observational Data. SIAM.
  11. Gu, Chong (2013). Smoothing Spline ANOVA Models (2nd ed.). Springer.
  12. Wood, S. N. (2017). Generalized Additive Models: An Introduction with R (2nd ed). Chapman & Hall/CRC. ISBN 978-1-58488-474-3.
  13. Eilers, P.H.C. and Marx B. (1996). "Flexible smoothing with B-splines and penalties". Statistical Science. 11 (2): 89–121.
  14. Ruppert, David; Wand, M. P.; Carroll, R. J. (2003). Semiparametric Regression. Cambridge University Press. ISBN 978-0-521-78050-6.

Further reading

  • Wahba, G. (1990). Spline Models for Observational Data. SIAM, Philadelphia.
  • Green, P. J. and Silverman, B. W. (1994). Nonparametric Regression and Generalized Linear Models. CRC Press.
  • De Boor, C. (2001). A Practical Guide to Splines (Revised Edition). Springer.
Categories: