<?xml-stylesheet type="text/xsl" href="../styles/pmathml.xsl"?>
<!-- saved from url=(0014)about:internet -->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:dsi="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xml:space="preserve"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"/><title>G10 Chapter Introduction : NAG Library, Mark 22</title><link rel="stylesheet" href="../styles/libdoc.css" type="text/css"/><script type="text/javascript">
   function showLevel(_levelId){
    var thisLevel = document.getElementById(_levelId);
    var thisplus = document.getElementById( _levelId.concat('plus'));
    var thisminus = document.getElementById( _levelId.concat('minus'));
    if(thisLevel.style.display != "block"){
     thisLevel.style.display = "block";
     thisplus.style.display = "none";
     thisminus.style.display = "inline";
     }
    else{
     thisLevel.style.display = "none";
     thisminus.style.display = "none";
     thisplus.style.display = "inline";
     }
    }
  </script></head><body><hr/><div><a class="chap" href="g10conts.xml">G10 Chapter Contents</a></div><div><a class="chapint" href="../../pdf/G10/g10intro.pdf">G10 Chapter Introduction (PDF version)</a></div>
<div><a class="htmltoc" href="../FRONTMATTER/manconts.xml">NAG Library Manual</a></div><hr/><h1 class="libdoc">NAG Library Chapter Introduction<br/><br/>G10 &#8211; Smoothing in Statistics</h1><div class="htmltoc">
<h2 class="htmltoc"><span class="htmltochead" onclick="showLevel('htmltoc');"><span class="htmltocplus" id="htmltocplus">+</span><span class="htmltocminus" id="htmltocminus">&#8722;</span></span>&#160;Contents</h2>
<div class="htmltocitem" id="htmltoc">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#scope">1&#160;&#160;<b>Scope of the Chapter</b></a>
</div><div class="htmltoc">
<span class="htmltoc" onclick="showLevel('tocbackground');"><span class="htmltocplus" id="tocbackgroundplus">+</span><span class="htmltocminus" id="tocbackgroundminus">&#8722;</span></span>
<a class="htmltoc" href="#background">2&#160;&#160;<b>Background to the Problems</b></a>
<div class="htmltocitem" id="tocbackground">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#intbackground1">2.1&#160;&#160;<b>Smoothing Methods</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#intbackground2">2.2&#160;&#160;<b>Smoothing Splines and Regression Models</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#intbackground3">2.3&#160;&#160;<b>Density Estimation</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#intbackground4">2.4&#160;&#160;<b>Smoothers for Time Series</b></a>
</div>
</div>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#available">3&#160;&#160;<b>Recommendations on Choice and Use of Available Routines</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#withdrawn">4&#160;&#160;<b>Routines Withdrawn or Scheduled for Withdrawal</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#references">5&#160;&#160;<b>References</b></a>
</div>
</div>
</div><h2 class="standard"><a class="sec" name="scope" id="scope"/>1&#160;&#160;Scope of the Chapter</h2>
<div class="paramtext">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.</div><h2 class="standard"><a class="sec" name="background" id="background"/>2&#160;&#160;Background to the Problems</h2><h3 class="standard"><a class="sec" name="intbackground1" id="intbackground1"/>2.1&#160;&#160;Smoothing Methods</h3>
<div class="paramtext">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.</div><div class="paramtext">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.</div><div class="paramtext">These smoothing methods can be used in a variety of ways, for example:
<ol class="listnumber"><li class="listnumber">producing smoothed plots to aid understanding;</li><li class="listnumber">identifying of a suitable parametric model from the shape of the smoothed data;</li><li class="listnumber">eliminating complex effects that are not of direct interest so that attention can be focused on the effects of interest.</li></ol>
</div><div class="paramtext">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.</div><div class="paramtext">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.</div><div class="paramtext">Smoothing methods can be used in three important areas of of statistics:  regression modelling, distribution modelling and time series modelling.</div><h3 class="standard"><a class="sec" name="intbackground2" id="intbackground2"/>2.2&#160;&#160;Smoothing Splines and Regression Models</h3>
<div class="paramtext">For a set of <m:math><m:mi>n</m:mi></m:math>&#160;observations  (<m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub><m:mo>,</m:mo><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:math>), <m:math><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:mi>n</m:mi></m:math>, the spline provides a flexible smooth function for situations in which a simple polynomial or nonlinear regression model is not suitable.</div><div class="paramtext">Cubic smoothing splines arise as the function, <m:math><m:mi>f</m:mi></m:math>, with continuous first derivative which minimizes

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:msub><m:mi>w</m:mi><m:mi>i</m:mi></m:msub>
<m:msup>
<m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub><m:mo>-</m:mo><m:mi>f</m:mi><m:mfenced separators=""><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:mfenced></m:mfenced>
<m:mn>2</m:mn></m:msup><m:mo>+</m:mo><m:mi>&#961;</m:mi><m:munderover><m:mo>&#8747;</m:mo><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow><m:mi>&#8734;</m:mi></m:munderover><m:msup><m:mfenced separators=""><m:msup><m:mi>f</m:mi><m:mrow><m:mo>&#8242;</m:mo><m:mo>&#8242;</m:mo></m:mrow></m:msup><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mfenced><m:mn>2</m:mn></m:msup><m:mrow><m:mi>d</m:mi><m:mi>x</m:mi></m:mrow><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

where <m:math><m:msub><m:mi>w</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;is the (optional) weight for the <m:math><m:mi>i</m:mi></m:math>th observation and <m:math><m:mi>&#961;</m:mi></m:math>&#160;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,  <m:math><m:mi>&#961;</m:mi></m:math>, weights these two aspects: larger values of  <m:math><m:mi>&#961;</m:mi></m:math>&#160;give a smoother fitted curve but, in general,  a poorer fit.</div><div class="paramtext">Splines are linear smoothers since the fitted values,  <m:math>
 <m:mover><m:mi>y</m:mi><m:mo>^</m:mo></m:mover>
 <m:mo>=</m:mo>
 <m:msup><m:mfenced separators=""><m:msub><m:mover><m:mi>y</m:mi><m:mo>^</m:mo></m:mover><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mover><m:mi>y</m:mi><m:mo>^</m:mo></m:mover><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mover><m:mi>y</m:mi><m:mo>^</m:mo></m:mover><m:mi>n</m:mi></m:msub></m:mfenced><m:mi mathvariant="normal">T</m:mi></m:msup>
</m:math>,  can be written as a linear function of the observed values  <m:math>
 <m:mi>y</m:mi>
 <m:mo>=</m:mo>
 <m:msup><m:mfenced separators=""><m:msub><m:mi>y</m:mi><m:mn>1</m:mn></m:msub><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>y</m:mi><m:mi>n</m:mi></m:msub></m:mfenced><m:mi mathvariant="normal">T</m:mi></m:msup>
</m:math>, that is,

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>y</m:mi><m:mo>^</m:mo></m:mover><m:mo>=</m:mo><m:mi>H</m:mi><m:mi>y</m:mi>
</m:math></td><td class="formula2"/></tr></table></div>

for a matrix <m:math><m:mi>H</m:mi></m:math>.  The degrees of freedom for the spline is <m:math><m:mi mathvariant="normal">trace</m:mi><m:mfenced separators=""><m:mi>H</m:mi></m:mfenced></m:math>&#160;giving residual degrees of freedom

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi mathvariant="normal">trace</m:mi><m:mfenced separators=""><m:mi>I</m:mi><m:mo>-</m:mo><m:mi>H</m:mi></m:mfenced><m:mo>=</m:mo><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:mfenced separators=""><m:mn>1</m:mn><m:mo>-</m:mo><m:msub><m:mi>h</m:mi><m:mrow><m:mi>i</m:mi><m:mi>i</m:mi></m:mrow></m:msub></m:mfenced><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The diagonal elements of <m:math><m:mi>H</m:mi></m:math>, <m:math><m:msub><m:mi>h</m:mi><m:mrow><m:mi>i</m:mi><m:mi>i</m:mi></m:mrow></m:msub></m:math>, are the leverages.</div><div class="paramtext">The parameter <m:math><m:mi>&#961;</m:mi></m:math>&#160;can be estimated in a number of ways.
<ol class="listnumber"><li class="listnumber">The degrees of freedom for the spline can be specified, i.e., find <m:math><m:mi>&#961;</m:mi></m:math>&#160;such that <m:math><m:mi mathvariant="normal">trace</m:mi><m:mfenced separators=""><m:mi>H</m:mi></m:mfenced><m:mo>=</m:mo><m:msub><m:mi>&#957;</m:mi><m:mn>0</m:mn></m:msub></m:math>&#160;for given <m:math><m:msub><m:mi>&#957;</m:mi><m:mn>0</m:mn></m:msub></m:math>.</li><li class="listnumber">Minimize the cross-validation (CV), i.e., find <m:math><m:mi>&#961;</m:mi></m:math>&#160;such that the CV is minimized, where

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtext>CV</m:mtext><m:mo>=</m:mo><m:mfrac><m:mn>1</m:mn><m:mi>n</m:mi></m:mfrac><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover>
<m:msup>
<m:mfenced separators=""><m:mfrac><m:msub><m:mi>r</m:mi><m:mi>i</m:mi></m:msub><m:mrow><m:mn>1</m:mn><m:mo>-</m:mo><m:msub><m:mi>h</m:mi><m:mrow><m:mi>i</m:mi><m:mi>i</m:mi></m:mrow></m:msub></m:mrow>
 </m:mfrac></m:mfenced>
<m:mn>2</m:mn></m:msup><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>
</li><li class="listnumber">Minimize generalized cross-validation (GCV), i.e., find <m:math><m:mi>&#961;</m:mi></m:math>&#160;such that the GCV is minimized, where

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtext>GCV</m:mtext><m:mo>=</m:mo><m:mi>n</m:mi>
<m:mfenced separators=""><m:mfrac><m:mrow><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:msubsup><m:mi>r</m:mi><m:mi>i</m:mi><m:mn>2</m:mn></m:msubsup></m:mrow>
<m:msup>
<m:mfenced separators=""><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover>
<m:mfenced separators=""><m:mn>1</m:mn><m:mo>-</m:mo><m:msub><m:mi>h</m:mi><m:mrow><m:mi>i</m:mi><m:mi>i</m:mi></m:mrow></m:msub></m:mfenced>
</m:mfenced>
<m:mn>2</m:mn></m:msup>
</m:mfrac></m:mfenced>
<m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>
</li></ol>
</div><h3 class="standard"><a class="sec" name="intbackground3" id="intbackground3"/>2.3&#160;&#160;Density Estimation</h3>
<div class="paramtext">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 <m:math><m:mi>n</m:mi></m:math>&#160;observations, <m:math><m:msub><m:mi>x</m:mi><m:mn>1</m:mn></m:msub></m:math>, <m:math><m:msub><m:mi>x</m:mi><m:mn>2</m:mn></m:msub><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>x</m:mi><m:mi>n</m:mi></m:msub></m:math>, from a distribution with unknown density function, <m:math><m:mi>f</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, find an estimate of the density function, <m:math><m:mover><m:mi>f</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>.  The simplest form of density estimator is the histogram; this may be defined by

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>f</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mn>1</m:mn><m:mrow><m:mi>n</m:mi><m:mi>h</m:mi></m:mrow>
 </m:mfrac><m:msub><m:mi>n</m:mi><m:mi>j</m:mi></m:msub><m:mtext>; &#8195;</m:mtext><m:mi>a</m:mi><m:mo>+</m:mo><m:mfenced separators=""><m:mi>j</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mi>h</m:mi><m:mo>&lt;</m:mo><m:mi>x</m:mi><m:mo>&lt;</m:mo><m:mi>a</m:mi><m:mo>+</m:mo><m:mi>j</m:mi><m:mi>h</m:mi><m:mtext>; &#8195;</m:mtext><m:mi>j</m:mi><m:mo>=</m:mo><m:mn>1</m:mn><m:mo>,</m:mo><m:mn>2</m:mn><m:mo>,</m:mo><m:mo>&#8230;</m:mo><m:mo>,</m:mo><m:msub><m:mi>n</m:mi><m:mi>s</m:mi></m:msub><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

where <m:math><m:msub><m:mi>n</m:mi><m:mi>j</m:mi></m:msub></m:math>&#160;is the number of observations falling in the interval <m:math><m:mi>a</m:mi><m:mo>+</m:mo><m:mfenced separators=""><m:mi>j</m:mi><m:mo>-</m:mo><m:mn>1</m:mn></m:mfenced><m:mi>h</m:mi></m:math>&#160;to <m:math><m:mi>a</m:mi><m:mo>+</m:mo><m:mi>j</m:mi><m:mi>h</m:mi></m:math>, <m:math><m:mi>a</m:mi></m:math>&#160;is the lower bound of the histogram and <m:math><m:mi>b</m:mi><m:mo>=</m:mo><m:msub><m:mi>n</m:mi><m:mi>s</m:mi></m:msub><m:mi>h</m:mi></m:math>&#160;is the upper bound.  The value <m:math><m:mi>h</m:mi></m:math>&#160;is known as the window width.  A simple development of this estimator would be the running histogram estimator

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>f</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mn>1</m:mn><m:mrow><m:mn>2</m:mn><m:mi>n</m:mi><m:mi>h</m:mi></m:mrow>
 </m:mfrac><m:msub><m:mi>n</m:mi><m:mi>x</m:mi></m:msub><m:mtext>; &#8195;</m:mtext><m:mi>a</m:mi><m:mo>&#8804;</m:mo><m:mi>x</m:mi><m:mo>&#8804;</m:mo><m:mi>b</m:mi><m:mtext>,</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

where <m:math><m:msub><m:mi>n</m:mi><m:mi>x</m:mi></m:msub></m:math>&#160;is the number of observations falling in the interval <m:math><m:mfenced open="[" close="]" separators=""><m:mi>x</m:mi><m:mo>-</m:mo><m:mi>h</m:mi><m:mo>:</m:mo><m:mi>x</m:mi><m:mo>+</m:mo><m:mi>h</m:mi></m:mfenced></m:math>.  This estimator can be written as

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>f</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mn>1</m:mn><m:mrow><m:mi>n</m:mi><m:mi>h</m:mi></m:mrow>
 </m:mfrac><m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo><m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:mi>w</m:mi>
<m:mfenced separators=""><m:mfrac><m:mrow><m:mi>x</m:mi><m:mo>-</m:mo><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:mrow><m:mi>h</m:mi></m:mfrac></m:mfenced>
</m:math></td><td class="formula2"/></tr></table></div>

for a function <m:math><m:mi>w</m:mi></m:math>&#160;where

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mtable columnalign="left">
 <m:mtr>
  <m:mtd><m:mi>w</m:mi><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:mtd>
  <m:mtd><m:mo>=</m:mo><m:mfrac other="small"><m:mn>1</m:mn><m:mn>2</m:mn></m:mfrac></m:mtd>
  <m:mtd><m:mtext>if</m:mtext><m:mo>-</m:mo><m:mn>1</m:mn><m:mo>&lt;</m:mo><m:mi>x</m:mi><m:mo>&lt;</m:mo><m:mn>1</m:mn></m:mtd>
 </m:mtr><m:mtr>
  <m:mtd/>
  <m:mtd><m:mo>=</m:mo><m:mn>0</m:mn></m:mtd>
  <m:mtd><m:mtext>otherwise.</m:mtext></m:mtd>
 </m:mtr>
</m:mtable>
</m:math></td><td class="formula2"/></tr></table></div>

The function <m:math><m:mi>w</m:mi></m:math>&#160;can be considered as a kernel function.  To produce a smoother density estimate, the kernel function, <m:math><m:mi>K</m:mi><m:mfenced separators=""><m:mi>t</m:mi></m:mfenced></m:math>,  which satisfies the following conditions can be used:

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:munderover><m:mo>&#8747;</m:mo><m:mrow><m:mo>-</m:mo><m:mi>&#8734;</m:mi></m:mrow><m:mi>&#8734;</m:mi></m:munderover><m:mi>K</m:mi><m:mfenced separators=""><m:mi>t</m:mi></m:mfenced><m:mrow><m:mi>d</m:mi><m:mi>t</m:mi></m:mrow><m:mo>=</m:mo><m:mn>1</m:mn>  <m:mtext>and &#8203;</m:mtext><m:mi>K</m:mi><m:mfenced separators=""><m:mi>t</m:mi></m:mfenced><m:mo>&#8805;</m:mo><m:mn>0.0</m:mn><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The kernel density estimator is therefore defined as

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mover><m:mi>f</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mn>1</m:mn><m:mrow><m:mi>n</m:mi><m:mi>h</m:mi></m:mrow>
 </m:mfrac> <m:munderover><m:mo>&#8721;</m:mo><m:mrow><m:mi>i</m:mi><m:mo>=</m:mo> <m:mn>1</m:mn></m:mrow><m:mi>n</m:mi></m:munderover><m:mi>K</m:mi>
<m:mfenced separators=""><m:mfrac><m:mrow><m:mi>x</m:mi><m:mo>-</m:mo><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:mrow><m:mi>h</m:mi></m:mfrac></m:mfenced>
<m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The choice of <m:math><m:mi>K</m:mi><m:mfenced separators=""><m:mo>&#183;</m:mo></m:mfenced></m:math>&#160;is usually not important,  but to ease computational burden use can be made of Gaussian kernel defined as

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi>K</m:mi><m:mfenced separators=""><m:mi>t</m:mi></m:mfenced><m:mo>=</m:mo><m:mfrac><m:mn>1</m:mn><m:msqrt><m:mn>2</m:mn><m:mi>&#960;</m:mi></m:msqrt></m:mfrac><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:msup><m:mi>t</m:mi><m:mn>2</m:mn></m:msup><m:mo>/</m:mo><m:mn>2</m:mn></m:mrow></m:msup><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The smoothness of the estimator, <m:math><m:mover><m:mi>f</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:mi>x</m:mi></m:mfenced></m:math>, depends on the window width, <m:math><m:mi>h</m:mi></m:math>.  In general, the larger the value  <m:math><m:mi>h</m:mi></m:math>&#160;is, the smoother the resulting density estimate is.  There is, however, the problem of oversmoothing when the value of <m:math><m:mi>h</m:mi></m:math>&#160;is too large and essential features of the distribution function are removed.  For example, if the distribution was bimodal, a large value of <m:math><m:mi>h</m:mi></m:math>&#160;may result in a unimodal estimate.  The value of <m:math><m:mi>h</m:mi></m:math>&#160;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  <m:math><m:mi>h</m:mi></m:math>&#160;can be aided by looking at plots of the density estimate for different values of <m:math><m:mi>h</m:mi></m:math>, or by using cross-validation methods; see <a class="ref" href="#ref506">Silverman (1990)</a>.</div><div class="paramtext"><a class="ref" href="#ref506">Silverman (1990)</a> shows how the Gaussian kernel density estimator can be computed using a fast Fourier transform (FFT).</div><h3 class="standard"><a class="sec" name="intbackground4" id="intbackground4"/>2.4&#160;&#160;Smoothers for Time Series</h3>
<div class="paramtext">If the data consists of a sequence of <m:math><m:mi>n</m:mi></m:math>&#160;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 <a class="ref" href="#ref122">Tukey (1977)</a> and <a class="ref" href="#ref124">Velleman and Hoaglin (1981)</a>.  The smoothers are based on the use of running medians to summarize overlapping segments; these provide a simple but flexible curve.</div><div class="paramtext">In EDA terminology, the fitted curve and the residuals are called the smooth and the rough respectively, so that

<div class="formula"><table class="formula"><tr><td class="formula"><m:math display="block">
<m:mi mathvariant="normal">Data</m:mi><m:mo>=</m:mo><m:mi mathvariant="normal">Smooth</m:mi><m:mo>+</m:mo><m:mi mathvariant="normal">Rough</m:mi><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

Using the notation of Tukey, one of the smoothers commonly used is 4253H,twice.  This consists of a running median of <m:math><m:mn>4</m:mn></m:math>, then <m:math><m:mn>2</m:mn></m:math>, then <m:math><m:mn>5</m:mn></m:math>, then <m:math><m:mn>3</m:mn></m:math>.  This is then followed by what is known as hanning.  Hanning is a running weighted mean, the weights being <m:math><m:mn>1</m:mn><m:mo>/</m:mo><m:mn>4</m:mn></m:math>, <m:math><m:mn>1</m:mn><m:mo>/</m:mo><m:mn>2</m:mn></m:math>&#160;and <m:math><m:mn>1</m:mn><m:mo>/</m:mo><m:mn>4</m:mn></m:math>.  The result of this smoothing is then &#8216;reroughed&#8217;.  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.</div><h2 class="standard"><a class="sec" name="available" id="available"/>3&#160;&#160;Recommendations on Choice and Use of Available Routines</h2>
<div class="paramtext">The following routines fit smoothing splines:
<table class="standard-100"><tr><td style="width:15%" class="libdoc" valign="top"><a class="rout" href="../G10/g10abf.xml">G10ABF</a></td><td valign="top">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 routine 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 <a class="ref" href="#ref501">Hastie and Tibshirani (1990)</a>.</td></tr><tr><td style="width:15%" class="libdoc" valign="top"><a class="rout" href="../G10/g10acf.xml">G10ACF</a></td><td valign="top">estimates the value of the smoothing parameter using one of three criteria and fits the cubic smoothing spline using that value.</td></tr></table>
<a class="rout" href="../G10/g10abf.xml">G10ABF</a> and <a class="rout" href="../G10/g10acf.xml">G10ACF</a> require the  <m:math><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;to be strictly increasing.  If two or more observations have the same  <m:math><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:math>-value then they should be replaced by a single observation with <m:math><m:msub><m:mi>y</m:mi><m:mi>i</m:mi></m:msub></m:math>&#160;equal to the (weighted) mean of the  <m:math><m:mi>y</m:mi></m:math>&#160;values and weight, <m:math><m:msub><m:mi>w</m:mi><m:mi>i</m:mi></m:msub></m:math>, equal to the sum of the weights.  This operation can be performed by <a class="rout" href="../G10/g10zaf.xml">G10ZAF</a>.</div><div class="paramtext">The following routine produces an estimate of the density function:
<table class="standard-100"><tr><td style="width:15%" class="libdoc" valign="top"><a class="rout" href="../G10/g10baf.xml">G10BAF</a></td><td valign="top">computes a density estimate using a Normal kernel.</td></tr></table>
</div><div class="paramtext">The following routine produces a smoothed estimate for a time series:
<table class="standard-100"><tr>
<td style="width:NaNem;" valign="baseline"><a class="rout" href="../G10/g10caf.xml">G10CAF</a></td>
<td valign="top">computes a smoothed series using running median smoothers.</td>
</tr></table>
</div><div class="paramtext">The following service routine is also available:
<table class="standard-100"><tr>
<td style="width:NaNem;" valign="baseline"><a class="rout" href="../G10/g10zaf.xml">G10ZAF</a></td>
<td valign="top">orders and weights the <m:math><m:mfenced separators=""><m:mi>x</m:mi><m:mo>,</m:mo><m:mi>y</m:mi></m:mfenced></m:math>&#160;input data to produce a dataset strictly monotonic in <m:math><m:mi>x</m:mi></m:math>.</td>
</tr></table>
</div><h2 class="standard"><a class="sec" name="withdrawn" id="withdrawn"/>4&#160;&#160;Routines Withdrawn or Scheduled for Withdrawal</h2>
<div class="paramtext">None.</div><h2 class="standard"><a class="sec" name="references" id="references"/>5&#160;&#160;References</h2><div class="paramtext"><a name="ref501" id="ref501"/>Hastie T J and Tibshirani R J (1990)  <i>Generalized Additive Models</i> Chapman and Hall </div>
<div class="paramtext"><a name="ref506" id="ref506"/>Silverman B W (1990)  <i>Density Estimation</i> Chapman and Hall </div>
<div class="paramtext"><a name="ref122" id="ref122"/>Tukey J W (1977)  <i>Exploratory Data Analysis</i> Addison&#8211;Wesley </div>
<div class="paramtext"><a name="ref124" id="ref124"/>Velleman P F and Hoaglin D C (1981)  <i>Applications, Basics, and Computing of Exploratory Data Analysis</i> Duxbury Press, Boston, MA </div><hr/><div><a class="chap" href="g10conts.xml">G10 Chapter Contents</a></div><div><a class="chapint" href="../../pdf/G10/g10intro.pdf">G10 Chapter Introduction (PDF version)</a></div>
<div><a class="htmltoc" href="../FRONTMATTER/manconts.xml">NAG Library Manual</a></div>
<div><hr/><a class="genint" href="../FRONTMATTER/copyright.xml">&#169; The Numerical Algorithms Group Ltd, Oxford, UK. 2009</a></div></body></html>
