Integer type:** int32**** int64**** nag_int** show int32 show int32 show int64 show int64 show nag_int show nag_int

G10 — Smoothing in Statistics

This chapter is concerned with methods for smoothing data. Included are methods for density estimation, smoothing time series data, and statistical applications of splines. These methods may also be viewed as nonparametric modelling.

Many of the methods used in statistics involve fitting a model, the form of which is determined by a small number of parameters, for example, a distribution model like the gamma distribution, a linear regression model or an autoregression model in time series. In these cases the fitting involves the estimation of the small number of parameters from the data. In modelling data with these models there are two important stages in addition to the estimation of the parameters; these are the identification of a suitable model, for example, the selection of a gamma distribution rather than a Weibull distribution, and the checking to see if the fitted model adequately fits the data. While these parametric models can be fairly flexible, they will not adequately fit all datasets, especially if the number of parameters is to be kept small.

Alternative models based on smoothing can be used. These models will not be written explicitly in terms of parameters. They are sufficiently flexible for a much wider range of situations than parametric models. The main requirement for such a model to be suitable is that the underlying models would be expected to be smooth, so excluding those situations where, for example, a step function would be expected.

These smoothing methods can be used in a variety of ways, for example:

- producing smoothed plots to aid understanding;
- identifying of a suitable parametric model from the shape of the smoothed data;
- eliminating complex effects that are not of direct interest so that attention can be focused on the effects of interest.

Several smoothing techniques make use of a smoothing parameter which can be either chosen by you or estimated from the data. The smoothing parameter balances the two criterion of smoothness of the fitted model and the closeness of the fit of the model to the data. Generally, the larger the smoothing parameter is, the smoother the fitted model will be, but for small values of the smoothing parameter the model will closely follow the data, and for large values the fit will be poorer.

The smoothing parameter can be either chosen using previous experience of a suitable value for such data, or estimated from the data. The estimation can be either formal, using a criterion such as the cross-validation, or informal by trying different values and examining the result by means of suitable graphs.

Smoothing methods can be used in three important areas of of statistics: regression modelling, distribution modelling and time series modelling.

For a set of n$n$ observations (y_{i},x_{i}${y}_{i},{x}_{i}$), i = 1,2, … ,n$i=1,2,\dots ,n$, the spline provides a flexible smooth function for situations in which a simple polynomial or nonlinear regression model is not suitable.

Cubic smoothing splines arise as the function, f$f$, with continuous first derivative which minimizes

where w_{i}${w}_{i}$ is the (optional) weight for the i$i$th observation and ρ$\rho $ is the smoothing parameter. This criterion consists of two parts: the first measures the fit of the curve and the second the smoothness of the curve. The value of the smoothing parameter, ρ$\rho $, weights these two aspects: larger values of ρ$\rho $ give a smoother fitted curve but, in general, a poorer fit.

$$\sum _{i=1}^{n}{w}_{i}{({y}_{i}-f\left({x}_{i}\right))}^{2}+\rho \underset{-\infty}{\overset{\infty}{\int}}{\left({f}^{\prime \prime}\left(x\right)\right)}^{2}dx\text{,}$$ |

Splines are linear smoothers since the fitted values,
ŷ
=
(ŷ_{1},ŷ_{2}, … ,ŷ_{n})^{T}
$\hat{y}={({\hat{y}}_{1},{\hat{y}}_{2},\dots ,{\hat{y}}_{n})}^{\mathrm{T}}$, can be written as a linear function of the observed values
y
=
(y_{1},y_{2}, … ,y_{n})^{T}
$y={({y}_{1},{y}_{2},\dots ,{y}_{n})}^{\mathrm{T}}$, that is,

for a matrix H$H$. The degrees of freedom for the spline is trace(H)$\mathrm{trace}\left(H\right)$ giving residual degrees of freedom

The diagonal elements of H$H$, h_{ii}${h}_{ii}$, are the leverages.

ŷ = Hy
$$\hat{y}=Hy$$ |

$$\mathrm{trace}(I-H)=\sum _{i=1}^{n}(1-{h}_{ii})\text{.}$$ |

The parameter ρ$\rho $ can be estimated in a number of ways.

- The degrees of freedom for the spline can be specified, i.e., find ρ$\rho $ such that trace(H) = ν
_{0}$\mathrm{trace}\left(H\right)={\nu}_{0}$ for given ν_{0}${\nu}_{0}$. - Minimize the cross-validation (CV), i.e., find ρ$\rho $ such that the CV is minimized, where
n CV = 1/n ∑ ((r _{i})/(1 − h_{ii}))^{2}.i = 1 $$\text{CV}=\frac{1}{n}\sum _{i=1}^{n}{\left(\frac{{r}_{i}}{1-{h}_{ii}}\right)}^{2}\text{.}$$ - Minimize generalized cross-validation (GCV), i.e., find ρ$\rho $ such that the GCV is minimized, where
GCV = n (( ∑ i = 1
^{n}ri^{2})/(

)) .(n ) ∑ (1 − hii)i = 1 ^{2}$$\text{GCV}=n\left(\frac{\sum _{i=1}^{n}{r}_{i}^{2}}{{\left(\sum _{i=1}^{n}(1-{h}_{ii})\right)}^{2}}\right)\text{.}$$

The object of density estimation is to produce from a set of observations a smooth nonparametric estimate of the unknown density function from which the observations were drawn. That is, given a sample of n$n$ observations, x_{1}${x}_{1}$, x_{2}, … ,x_{n}${x}_{2},\dots ,{x}_{n}$, from a distribution with unknown density function, f(x)$f\left(x\right)$, find an estimate of the density function, f̂(x)$\hat{f}\left(x\right)$. The simplest form of density estimator is the histogram; this may be defined by

where n_{j}${n}_{j}$ is the number of observations falling in the interval a + (j − 1)h$a+(j-1)h$ to a + jh$a+jh$, a$a$ is the lower bound of the histogram and b = n_{s}h$b={n}_{s}h$ is the upper bound. The value h$h$ is known as the window width. A simple development of this estimator would be the running histogram estimator

where n_{x}${n}_{x}$ is the number of observations falling in the interval [x − h : x + h]$[x-h:x+h]$. This estimator can be written as

for a function w$w$ where

The function w$w$ can be considered as a kernel function. To produce a smoother density estimate, the kernel function, K(t)$K\left(t\right)$, which satisfies the following conditions can be used:

The kernel density estimator is therefore defined as

The choice of K( · )$K(\xb7)$ is usually not important, but to ease computational burden use can be made of Gaussian kernel defined as

The smoothness of the estimator, f̂(x)$\hat{f}\left(x\right)$, depends on the window width, h$h$. In general, the larger the value h$h$ is, the smoother the resulting density estimate is. There is, however, the problem of oversmoothing when the value of h$h$ is too large and essential features of the distribution function are removed. For example, if the distribution was bimodal, a large value of h$h$ may result in a unimodal estimate. The value of h$h$ has to be chosen such that the essential shape of the distribution is retained while effects due only to the observed sample are smoothed out. The choice of h$h$ can be aided by looking at plots of the density estimate for different values of h$h$, or by using cross-validation methods; see Silverman (1990).

f̂(x) = 1/(nh)n _{j}; a + (j − 1)h < x < a + jh; j = 1,2, … ,n_{s},
$$\hat{f}\left(x\right)=\frac{1}{nh}{n}_{j}\text{; \hspace{1em}}a+(j-1)h<x<a+jh\text{; \hspace{1em}}j=1,2,\dots ,{n}_{s}\text{,}$$ |

f̂(x) = 1/(2nh)n _{x}; a ≤ x ≤ b,
$$\hat{f}\left(x\right)=\frac{1}{2nh}{n}_{x}\text{; \hspace{1em}}a\le x\le b\text{,}$$ |

$$\hat{f}\left(x\right)=\frac{1}{nh}\sum _{i=1}^{n}w\left(\frac{x-{x}_{i}}{h}\right)$$ |

$$\begin{array}{lll}w\left(x\right)& =\frac{1}{2}& \text{if}-1<x<1\\ & =0& \text{otherwise.}\end{array}$$ |

$$\underset{-\infty}{\overset{\infty}{\int}}K\left(t\right)dt=1\text{and}K\left(t\right)\ge 0.0\text{.}$$ |

$$\hat{f}\left(x\right)=\frac{1}{nh}\sum _{i=1}^{n}K\left(\frac{x-{x}_{i}}{h}\right)\text{.}$$ |

K(t) = 1/(sqrt(2π))e ^{ − t2 / 2}.
$$K\left(t\right)=\frac{1}{\sqrt{2\pi}}{e}^{-{t}^{2}/2}\text{.}$$ |

Silverman (1990) shows how the Gaussian kernel density estimator can be computed using a fast Fourier transform (FFT).

If the data consists of a sequence of n$n$ observations recorded at equally spaced intervals, usually a time series, several robust smoothers are available. The fitted curve is intended to be robust to any outlying observations in the sequence, hence the techniques employed primarily make use of medians rather than means. These ideas come from the field of exploratory data analysis (EDA); see Tukey (1977) and Velleman and Hoaglin (1981). The smoothers are based on the use of running medians to summarise overlapping segments; these provide a simple but flexible curve.

In EDA terminology, the fitted curve and the residuals are called the smooth and the rough respectively, so that

Using the notation of Tukey, one of the smoothers commonly used is 4253H,twice. This consists of a running median of 4$4$, then 2$2$, then 5$5$, then 3$3$. This is then followed by what is known as hanning. Hanning is a running weighted mean, the weights being 1 / 4$1/4$, 1 / 2$1/2$ and 1 / 4$1/4$. The result of this smoothing is then ‘reroughed’. This involves computing residuals from the computed fit, applying the same smoother to the residuals and adding the result to the smooth of the first pass.

Data = Smooth + Rough.
$$\mathrm{Data}=\mathrm{Smooth}+\mathrm{Rough}\text{.}$$ |

The following functions fit smoothing splines:

- nag_smooth_fit_spline (g10ab) computes a cubic smoothing spline for a given value of the smoothing parameter. The results returned include the values of leverages and the coefficients of the cubic spline. Options allow only parts of the computation to be performed when the function is used to estimate the value of the smoothing parameter or as when it is part of an iterative procedure such as that used in fitting generalized additive models; see Hastie and Tibshirani (1990).
- nag_smooth_fit_spline_parest (g10ac) estimates the value of the smoothing parameter using one of three criteria and fits the cubic smoothing spline using that value.

nag_smooth_fit_spline (g10ab) and nag_smooth_fit_spline_parest (g10ac) require the x_{i}${x}_{i}$ to be strictly increasing. If two or more observations have the same x_{i}${x}_{i}$-value then they should be replaced by a single observation with y_{i}${y}_{i}$ equal to the (weighted) mean of the y$y$ values and weight, w_{i}${w}_{i}$, equal to the sum of the weights. This operation can be performed by nag_smooth_data_order (g10za).

The following function produces an estimate of the density function:

- nag_smooth_kerndens_gauss (g10ba) computes a density estimate using a Normal kernel.

The following function produces a smoothed estimate for a time series:

- nag_smooth_data_runningmedian (g10ca) computes a smoothed series using running median smoothers.

The following service function is also available:

- nag_smooth_data_order (g10za) orders and weights the (x,y)$(x,y)$ input data to produce a dataset strictly monotonic in x$x$.

Hastie T J and Tibshirani R J (1990) *Generalized Additive Models* Chapman and Hall

Silverman B W (1990) *Density Estimation* Chapman and Hall

Tukey J W (1977) *Exploratory Data Analysis* Addison–Wesley

Velleman P F and Hoaglin D C (1981) *Applications, Basics, and Computing of Exploratory Data Analysis* Duxbury Press, Boston, MA

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013