hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox Chapter Introduction

G10 — Smoothing in Statistics

Scope of the Chapter

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.

Background to the Problems

Smoothing Methods

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:
  1. producing smoothed plots to aid understanding;
  2. identifying of a suitable parametric model from the shape of the smoothed data;
  3. 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.

Smoothing Splines and Regression Models

For a set of nn observations (yi,xiyi,xi), i = 1,2,,ni=1,2,,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, ff, with continuous first derivative which minimizes
n
wi(yif(xi))2 + ρ(f(x))2dx,
i = 1
i=1nwi (yi-f(xi)) 2+ρ-(f(x))2dx,
where wiwi is the (optional) weight for the iith observation and ρρ 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, ρρ, weights these two aspects: larger values of ρρ give a smoother fitted curve but, in general, a poorer fit.
Splines are linear smoothers since the fitted values, = (1,2,,n)T y^ = (y^1,y^2,,y^n)T , can be written as a linear function of the observed values y = (y1,y2,,yn)T y = (y1,y2,,yn)T , that is,
= Hy
y^=Hy
for a matrix HH. The degrees of freedom for the spline is trace(H)trace(H) giving residual degrees of freedom
n
trace(IH) = (1hii).
i = 1
trace(I-H)=i=1n(1-hii).
The diagonal elements of HH, hiihii, are the leverages.
The parameter ρρ can be estimated in a number of ways.
  1. The degrees of freedom for the spline can be specified, i.e., find ρρ such that trace(H) = ν0trace(H)=ν0 for given ν0ν0.
  2. Minimize the cross-validation (CV), i.e., find ρρ such that the CV is minimized, where
    n
    CV = 1/n((ri)/(1hii))2.
    i = 1
    CV=1ni=1n (ri1-hii ) 2.
  3. Minimize generalized cross-validation (GCV), i.e., find ρρ such that the GCV is minimized, where
    GCV = n (( ∑ i = 1nri2)/(
    (n ) ∑ (1 − hii)i = 1 2
    )) .
    GCV=n (i=1nri2 (i=1n (1-hii) ) 2 ) .

Density Estimation

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 nn observations, x1x1, x2,,xnx2,,xn, from a distribution with unknown density function, f(x)f(x), find an estimate of the density function, (x)f^(x). The simplest form of density estimator is the histogram; this may be defined by
(x) = 1/(nh)nj;  a + (j1)h < x < a + jh;  j = 1,2,,ns,
f^(x)=1nh nj;  a+(j-1)h<x<a+jh;  j=1,2,,ns,
where njnj is the number of observations falling in the interval a + (j1)ha+(j-1)h to a + jha+jh, aa is the lower bound of the histogram and b = nshb=nsh is the upper bound. The value hh is known as the window width. A simple development of this estimator would be the running histogram estimator
(x) = 1/(2nh)nx;  axb,
f^(x)=12nh nx;  axb,
where nxnx is the number of observations falling in the interval [xh : x + h][x-h:x+h]. This estimator can be written as
n
(x) = 1/(nh)w((xxi)/h)
i = 1
f^(x)=1nh i=1nw (x-xih)
for a function ww where
w(x) = (1/2) if1 < x < 1
= 0 otherwise.
w(x) =12 if-1<x<1 =0 otherwise.
The function ww can be considered as a kernel function. To produce a smoother density estimate, the kernel function, K(t)K(t), which satisfies the following conditions can be used:
K(t)dt = 1and ​K(t)0.0.
-K(t)dt=1 and ​K(t)0.0.
The kernel density estimator is therefore defined as
n
(x) = 1/(nh)K((xxi)/h).
i = 1
f^(x)=1nh i= 1nK (x-xih) .
The choice of K( · )K(·) is usually not important, but to ease computational burden use can be made of Gaussian kernel defined as
K(t) = 1/(sqrt(2π))et2 / 2.
K(t)=12πe-t2/2.
The smoothness of the estimator, (x)f^(x), depends on the window width, hh. In general, the larger the value hh is, the smoother the resulting density estimate is. There is, however, the problem of oversmoothing when the value of hh is too large and essential features of the distribution function are removed. For example, if the distribution was bimodal, a large value of hh may result in a unimodal estimate. The value of hh 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 hh can be aided by looking at plots of the density estimate for different values of hh, or by using cross-validation methods; see Silverman (1990).
Silverman (1990) shows how the Gaussian kernel density estimator can be computed using a fast Fourier transform (FFT).

Smoothers for Time Series

If the data consists of a sequence of nn 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
Data = Smooth + Rough.
Data=Smooth+Rough.
Using the notation of Tukey, one of the smoothers commonly used is 4253H,twice. This consists of a running median of 44, then 22, then 55, then 33. This is then followed by what is known as hanning. Hanning is a running weighted mean, the weights being 1 / 41/4, 1 / 21/2 and 1 / 41/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.

Recommendations on Choice and Use of Available Functions

The following functions fit smoothing splines:
nag_smooth_fit_spline (g10ab) and nag_smooth_fit_spline_parest (g10ac) require the xixi to be strictly increasing. If two or more observations have the same xixi-value then they should be replaced by a single observation with yiyi equal to the (weighted) mean of the yy values and weight, wiwi, 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:
The following function produces a smoothed estimate for a time series:
The following service function is also available:

Functionality Index

Compute smoothed data sequence, 
    running median smoothers nag_smooth_data_runningmedian (g10ca)
Fit cubic smoothing spline, 
    smoothing parameter estimated nag_smooth_fit_spline_parest (g10ac)
    smoothing parameter given nag_smooth_fit_spline (g10ab)
Kernel density estimation, 
    Gaussian kernel nag_smooth_kerndens_gauss (g10ba)
Reorder data to give ordered distinct observations nag_smooth_data_order (g10za)

References

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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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