<?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>G10BAF : 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="rout" href="../../pdf/G10/g10baf.pdf">G10BAF (PDF version)</a></div><div><a class="chap" href="g10conts.xml">G10 Chapter Contents</a></div><div><a class="chapint" href="g10intro.xml">G10 Chapter Introduction</a></div>
<div><a class="htmltoc" href="../FRONTMATTER/manconts.xml">NAG Library Manual</a></div><hr/><h1 class="libdoc">NAG Library Routine Document<br/><br/>G10BAF</h1><div class="paramtext"><div class="header"><b>Note:</b>&#160; before using this routine, please read the Users' Note for your implementation to check the interpretation of <span class="bitalic">bold italicised</span> terms and other implementation-dependent details.</div></div> 
<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="#purpose">1&#160;&#160;<b>Purpose</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#specification">2&#160;&#160;<b>Specification</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#description">3&#160;&#160;<b>Description</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#references">4&#160;&#160;<b>References</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#parameters">5&#160;&#160;<b>Parameters</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#errors">6&#160;&#160;<b>Error Indicators and Warnings</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#accuracy">7&#160;&#160;<b>Accuracy</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#fcomments">8&#160;&#160;<b>Further Comments</b></a>
</div><div class="htmltoc">
<span class="htmltoc" onclick="showLevel('tocexample');"><span class="htmltocplus" id="tocexampleplus">+</span><span class="htmltocminus" id="tocexampleminus">&#8722;</span></span>
<a class="htmltoc" href="#example">9&#160;&#160;<b>Example</b></a>
<div class="htmltocitem" id="tocexample">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examtext">9.1&#160;&#160;<b>Program Text</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examdata">9.2&#160;&#160;<b>Program Data</b></a>
</div><div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#examresults">9.3&#160;&#160;<b>Program Results</b></a>
</div>
</div>
</div>
</div>
</div><h2 class="standard"><a class="sec" name="purpose" id="purpose"/>1&#160;&#160;Purpose</h2>
<div class="paramtext">G10BAF performs kernel density estimation using a Gaussian kernel.</div><h2 class="standard"><a class="sec" name="specification" id="specification"/>2&#160;&#160;Specification</h2>
<table class="fspec"><tr><td class="tdfspec1">SUBROUTINE&#160;G10BAF&#160;(</td><td class="tdfspec2"><a class="arg" href="#N">N</a>, <a class="arg" href="#X">X</a>, <a class="arg" href="#WINDOW">WINDOW</a>, <a class="arg" href="#SLO">SLO</a>, <a class="arg" href="#SHI">SHI</a>, <a class="arg" href="#NS">NS</a>, <a class="arg" href="#SMOOTH">SMOOTH</a>, <a class="arg" href="#T">T</a>, <a class="arg" href="#USEFFT">USEFFT</a>, <a class="arg" href="#FFT">FFT</a>, <a class="arg" href="#IFAIL">IFAIL</a>)</td></tr><tr><td class="tdfspec1">INTEGER</td><td class="tdfspec2">N, NS, IFAIL</td></tr><tr><td class="tdfspec1"><b><i>double&#160;precision</i></b></td><td class="tdfspec2">X(N), WINDOW, SLO, SHI, SMOOTH(NS), T(NS), FFT(NS)</td></tr><tr><td class="tdfspec1">LOGICAL</td><td class="tdfspec2">USEFFT</td></tr></table><h2 class="standard"><a class="sec" name="description" id="description"/>3&#160;&#160;Description</h2>
<div class="paramtext">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:mo>,</m:mo><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>, 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>, may be required.  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 other="small"><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 to 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.  To produce a smoother density estimate a kernel method can be used.  A kernel function, <m:math><m:mi>K</m:mi><m:mfenced separators=""><m:mi>t</m:mi></m:mfenced></m:math>, satisfies the conditions:

<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>&#8195; and &#8195;</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</m:mn><m:mtext>.</m:mtext>
</m:math></td><td class="formula2"/></tr></table></div>

The kernel density estimator is then 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 other="small"><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:math>&#160;is usually not important but to ease the computational burden use can be made of the 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 depends on the window width <m:math><m:mi>h</m:mi></m:math>.  The larger the value of <m:math><m:mi>h</m:mi></m:math>&#160;the smoother the density estimate.  The value of <m:math><m:mi>h</m:mi></m:math>&#160;can be chosen by examining plots of the smoothed density for different values of <m:math><m:mi>h</m:mi></m:math>&#160;or by using cross-validation methods (see <a class="ref" href="#ref506">Silverman (1990)</a>).</div><div class="paramtext"><a class="ref" href="#ref505">Silverman (1982)</a> and <a class="ref" href="#ref506">Silverman (1990)</a> show how the Gaussian kernel density estimator can be computed using a fast Fourier transform (<a class="arg" href="#FFT">FFT</a>).  In order to compute the kernel density estimate over the range <m:math><m:mi>a</m:mi></m:math>&#160;to <m:math><m:mi>b</m:mi></m:math>&#160;the following steps are required.
<table class="standard-100"><tr>
<td style="width:2.1em;" valign="baseline"><a name="itemi" id="itemi"/>(i)</td>
<td valign="top">Discretize the data to give <m:math><m:msub><m:mi>n</m:mi><m:mi>s</m:mi></m:msub></m:math>&#160;equally spaced points  <m:math><m:msub><m:mi>t</m:mi><m:mi>l</m:mi></m:msub></m:math>&#160;with weights <m:math><m:msub><m:mi>&#958;</m:mi><m:mi>l</m:mi></m:msub></m:math>&#160;(see <a class="ref" href="#ref504">Jones and Lotwick (1984)</a>).</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline"><a name="itemii" id="itemii"/>(ii)</td>
<td valign="top">Compute the <a class="arg" href="#FFT">FFT</a> of the weights <m:math><m:msub><m:mi>&#958;</m:mi><m:mi>l</m:mi></m:msub></m:math>&#160;to give <m:math><m:msub><m:mi>Y</m:mi><m:mi>l</m:mi></m:msub></m:math>.</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline"><a name="itemiii" id="itemiii"/>(iii)</td>
<td valign="top">Compute <m:math><m:msub><m:mi>&#950;</m:mi><m:mi>l</m:mi></m:msub><m:mo>=</m:mo><m:msup><m:mi>e</m:mi><m:mrow><m:mo>-</m:mo><m:mfrac other="small"><m:mn>1</m:mn><m:mn>2</m:mn></m:mfrac><m:msup><m:mi>h</m:mi><m:mn>2</m:mn></m:msup><m:msubsup><m:mi>s</m:mi><m:mi>l</m:mi><m:mn>2</m:mn></m:msubsup></m:mrow></m:msup><m:msub><m:mi>Y</m:mi><m:mi>l</m:mi></m:msub></m:math>&#160;where <m:math><m:msub><m:mi>s</m:mi><m:mi>l</m:mi></m:msub><m:mo>=</m:mo><m:mn>2</m:mn><m:mi>&#960;</m:mi><m:mi>l</m:mi><m:mo>/</m:mo><m:mfenced separators=""><m:mi>b</m:mi><m:mo>-</m:mo><m:mi>a</m:mi></m:mfenced></m:math>.</td>
</tr><tr>
<td style="width:2.1em;" valign="baseline"><a name="itemiv" id="itemiv"/>(iv)</td>
<td valign="top">Find the inverse <a class="arg" href="#FFT">FFT</a> of <m:math><m:msub><m:mi>&#950;</m:mi><m:mi>l</m:mi></m:msub></m:math>&#160;to give  <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>.</td>
</tr></table>
</div><div class="paramtext">To compute the kernel density estimate for further values of  <m:math><m:mi>h</m:mi></m:math>&#160;only steps <a class="item" href="#itemiii">(iii)</a> and <a class="item" href="#itemiv">(iv)</a> need be repeated.</div><h2 class="standard"><a class="sec" name="references" id="references"/>4&#160;&#160;References</h2><div class="paramtext"><a name="ref504" id="ref504"/>Jones M C and Lotwick H W (1984)  Remark AS R50. A remark on algorithm AS 176 <i>Appl. Statist.</i> <b>33</b> 120&#8211;122 </div>
<div class="paramtext"><a name="ref505" id="ref505"/>Silverman B W (1982)  Algorithm AS 176. Kernel density estimation using the fast Fourier transform <i>Appl. Statist.</i> <b>31</b> 93&#8211;99 </div>
<div class="paramtext"><a name="ref506" id="ref506"/>Silverman B W (1990)  <i>Density Estimation</i> Chapman and Hall </div><h2 class="standard"><a class="sec" name="parameters" id="parameters"/>5&#160;&#160;Parameters</h2>
<dl><dt class="paramhead"><a name="N" id="N"/>1: &#160;&#160;&#8194; N &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: 

<m:math><m:mi>n</m:mi></m:math>, the number of observations in the sample.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>0</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="X" id="X"/>2: &#160;&#160;&#8194; X(<a class="arg" href="#N">N</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: the <m:math><m:mi>n</m:mi></m:math>&#160;observations, <m:math><m:msub><m:mi>x</m:mi><m:mi>i</m:mi></m:msub></m:math>, for <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>.</div></dd><dt class="paramhead"><a name="WINDOW" id="WINDOW"/>3: &#160;&#160;&#8194; WINDOW &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: <m:math><m:mi>h</m:mi></m:math>, the window width.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#WINDOW"><m:mi mathcolor="#EE0000" mathvariant="bold">WINDOW</m:mi></m:maction><m:mo>&gt;</m:mo><m:mn>0.0</m:mn></m:math>.
</div></dd><dt class="paramhead"><a name="SLO" id="SLO"/>4: &#160;&#160;&#8194; SLO &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: <m:math><m:mi>a</m:mi></m:math>, the lower limit of the interval on which the estimate is calculated. For most applications <a class="arg" href="#SLO">SLO</a> should be at least three window widths below the lowest data point.</div><div class="paramtext"><i>Constraint</i>:
  <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#SLO"><m:mi mathcolor="#EE0000" mathvariant="bold">SLO</m:mi></m:maction><m:mo>&lt;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#SHI"><m:mi mathcolor="#EE0000" mathvariant="bold">SHI</m:mi></m:maction></m:math>.
</div></dd><dt class="paramhead"><a name="SHI" id="SHI"/>5: &#160;&#160;&#8194; SHI &#8211; <span class="bitalic">double precision</span><span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: <m:math><m:mi>b</m:mi></m:math>, the upper limit of the interval on which the estimate is calculated. For most applications <a class="arg" href="#SHI">SHI</a> should be at least three window widths above the highest data point.</div></dd><dt class="paramhead"><a name="NS" id="NS"/>6: &#160;&#160;&#8194; NS &#8211; INTEGER<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: 

the number of points at which the estimate is calculated, <m:math><m:msub><m:mi>n</m:mi><m:mi>s</m:mi></m:msub></m:math>.</div><div class="paramtext"><i>Constraints</i>:
   <div class="paramtext"/><ul class="listcons">
<li class="listcons"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#NS"><m:mi mathcolor="#EE0000" mathvariant="bold">NS</m:mi></m:maction><m:mo>&#8805;</m:mo><m:mn>2</m:mn></m:math>;</li>
<li class="listcons">The largest prime factor of <a class="arg" href="#NS">NS</a> must not exceed <m:math><m:mn>19</m:mn></m:math>, and the total number of prime factors of <a class="arg" href="#NS">NS</a>, counting repetitions, must not exceed <m:math><m:mn>20</m:mn></m:math>.</li>
</ul></div></dd><dt class="paramhead"><a name="SMOOTH" id="SMOOTH"/>7: &#160;&#160;&#8194; SMOOTH(<a class="arg" href="#NS">NS</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: the <m:math><m:msub><m:mi>n</m:mi><m:mi>s</m:mi></m:msub></m:math>&#160;values of the density estimate, <m:math><m:mover><m:mi>f</m:mi><m:mo>^</m:mo></m:mover><m:mfenced separators=""><m:msub><m:mi>t</m:mi><m:mi>l</m:mi></m:msub></m:mfenced></m:math>, for <m:math><m:mi>l</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:math>.</div></dd><dt class="paramhead"><a name="T" id="T"/>8: &#160;&#160;&#8194; T(<a class="arg" href="#NS">NS</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Output</span></dt><dd><div class="paramtext"><i>On exit</i>: the points at which the estimate is calculated, <m:math><m:msub><m:mi>t</m:mi><m:mi>l</m:mi></m:msub></m:math>, for <m:math><m:mi>l</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:math>.</div></dd><dt class="paramhead"><a name="USEFFT" id="USEFFT"/>9: &#160;&#160;&#8194; USEFFT &#8211; LOGICAL<span class="pclass">Input</span></dt><dd><div class="paramtext"><i>On entry</i>: must be set to .FALSE. if the values of <m:math><m:msub><m:mi>Y</m:mi><m:mi>l</m:mi></m:msub></m:math>&#160;are to be calculated by G10BAF and to .TRUE. if they have been computed by a previous call to G10BAF and are provided in <a class="arg" href="#FFT">FFT</a>. If <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#USEFFT"><m:mi mathcolor="#EE0000" mathvariant="bold">USEFFT</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.TRUE.</m:mi></m:math>&#160;then the arguments <a class="arg" href="#N">N</a>, <a class="arg" href="#SLO">SLO</a>, <a class="arg" href="#SHI">SHI</a>, <a class="arg" href="#NS">NS</a> and <a class="arg" href="#FFT">FFT</a> must remain unchanged from the previous call to G10BAF with <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#USEFFT"><m:mi mathcolor="#EE0000" mathvariant="bold">USEFFT</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.FALSE.</m:mi></m:math>.</div></dd><dt class="paramhead"><a name="FFT" id="FFT"/>10: &#8194; FFT(<a class="arg" href="#NS">NS</a>) &#8211; <span class="bitalic">double precision</span> array<span class="pclass">Input/Output</span></dt><dd><div class="paramtext"><i>On entry</i>: if <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#USEFFT"><m:mi mathcolor="#EE0000" mathvariant="bold">USEFFT</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.TRUE.</m:mi></m:math>, then <a class="arg" href="#FFT">FFT</a> must contain the fast Fourier transform of the weights of the discretized data, <m:math><m:msub><m:mi>&#958;</m:mi><m:mi>l</m:mi></m:msub></m:math>, for <m:math><m:mi>l</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:math>. Otherwise <a class="arg" href="#FFT">FFT</a> need not be set.</div>
<div class="paramtext"><i>On exit</i>: the fast Fourier transform of the weights of the discretized data, <m:math><m:msub><m:mi>&#958;</m:mi><m:mi>l</m:mi></m:msub></m:math>, for <m:math><m:mi>l</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:math>.</div></dd><dt class="paramhead"><a name="IFAIL" id="IFAIL"/>11: &#8194; IFAIL &#8211; INTEGER<span class="pclass">Input/Output</span></dt><dd>
<div class="paramtext"><i>On entry</i>: <a class="arg" href="#IFAIL">IFAIL</a> must be set to <m:math><m:mn>0</m:mn></m:math>, <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>. If you are unfamiliar with this parameter you should refer to <a class="sec" href="../GENINT/essint.xml#library3">Section 3.3</a> in  the Essential Introduction for details.</div>
<div class="paramtext"><i>On exit</i>: <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;unless the routine detects an error (see <a class="sec" href="#errors">Section 6</a>). <div class="paramtext">For environments where it might be inappropriate to halt program execution when an error is detected, the value <m:math><m:mrow><m:mo>-</m:mo><m:mn>1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn>1</m:mn></m:math>&#160;is recommended.  If the output of error messages is undesirable, then the value <m:math><m:mn>1</m:mn></m:math>&#160;is recommended.  Otherwise, if you are not familiar with this parameter, the recommended value is <m:math><m:mn>0</m:mn></m:math>.  <b>When the value <m:math><m:mrow><m:mo>-</m:mo><m:mn mathvariant="bold">1</m:mn></m:mrow><m:mtext>&#8203; or &#8203;</m:mtext><m:mn mathvariant="bold">1</m:mn></m:math>&#160;is used it is essential to test the value of <a class="arg" href="#IFAIL">IFAIL</a> on exit.</b></div></div></dd></dl><h2 class="standard"><a class="sec" name="errors" id="errors"/>6&#160;&#160;Error Indicators and Warnings</h2>
<div class="paramtext">If on entry <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">0</m:mn></m:maction></m:math>&#160;or <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#errors"><m:mn mathcolor="#003399" mathvariant="bold">-1</m:mn></m:maction></m:math>, explanatory error messages are output on the current error message unit (as defined by <a class="rout" href="../X04/x04aaf.xml">X04AAF</a>).</div><div class="paramtext">Errors or warnings detected by the routine:</div>
<dl class="ifail">
<dt class="errorhead"><a name="IFeq1" id="IFeq1"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>1</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#N"><m:mi mathcolor="#EE0000" mathvariant="bold">N</m:mi></m:maction><m:mo>&#8804;</m:mo><m:mn>0</m:mn></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#NS"><m:mi mathcolor="#EE0000" mathvariant="bold">NS</m:mi></m:maction><m:mo>&lt;</m:mo><m:mn>2</m:mn></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#SHI"><m:mi mathcolor="#EE0000" mathvariant="bold">SHI</m:mi></m:maction><m:mo>&#8804;</m:mo><m:maction actiontype="link" dsi:type="simple" dsi:href="#SLO"><m:mi mathcolor="#EE0000" mathvariant="bold">SLO</m:mi></m:maction></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90"><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#WINDOW"><m:mi mathcolor="#EE0000" mathvariant="bold">WINDOW</m:mi></m:maction><m:mo>&#8804;</m:mo><m:mn>0.0</m:mn></m:math>.</td></tr></table>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq2" id="IFeq2"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>2</m:mn></m:math></dt>
<dd>
<table class="ifail"><tr><td class="ifail1">On&#160;entry,</td><td class="ifail2-90">G10BAF has been called with <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#USEFFT"><m:mi mathcolor="#EE0000" mathvariant="bold">USEFFT</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.TRUE.</m:mi></m:math>&#160;but the routine  has not been called previously with <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#USEFFT"><m:mi mathcolor="#EE0000" mathvariant="bold">USEFFT</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.FALSE.</m:mi></m:math>,</td></tr><tr><td class="ifail1">or</td><td class="ifail2-90">G10BAF has been called with <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#USEFFT"><m:mi mathcolor="#EE0000" mathvariant="bold">USEFFT</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.TRUE.</m:mi></m:math>&#160;but some of the arguments <a class="arg" href="#N">N</a>, <a class="arg" href="#SLO">SLO</a>, <a class="arg" href="#SHI">SHI</a>, <a class="arg" href="#NS">NS</a> have been changed since the previous call to  G10BAF with <m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#USEFFT"><m:mi mathcolor="#EE0000" mathvariant="bold">USEFFT</m:mi></m:maction><m:mo>=</m:mo><m:mi mathvariant="normal">.FALSE.</m:mi></m:math>.</td></tr></table>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq3" id="IFeq3"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>3</m:mn></m:math></dt>
<dd>
<div class="paramtext">On entry, at least one prime factor of <a class="arg" href="#NS">NS</a> is greater than <m:math><m:mn>19</m:mn></m:math>&#160;or <a class="arg" href="#NS">NS</a> has more than <m:math><m:mn>20</m:mn></m:math>&#160;prime factors (see <a class="rout" href="../C06/c06eaf.xml">C06EAF</a>).</div>
</dd>
</dl><dl class="ifail">
<dt class="errorhead"><a name="IFeq4" id="IFeq4"/><m:math><m:maction actiontype="link" dsi:type="simple" dsi:href="#IFAIL"><m:mi mathcolor="#EE0000" mathvariant="bold">IFAIL</m:mi></m:maction><m:mo>=</m:mo><m:mn>4</m:mn></m:math></dt>
<dd>
<div class="paramtext">On entry, the interval given by <a class="arg" href="#SLO">SLO</a> to <a class="arg" href="#SHI">SHI</a> does not extend beyond three window widths at either extreme of the dataset.  This may distort the density estimate in some cases.</div>
</dd>
</dl><h2 class="standard"><a class="sec" name="accuracy" id="accuracy"/>7&#160;&#160;Accuracy</h2>
<div class="paramtext">See <a class="ref" href="#ref504">Jones and Lotwick (1984)</a> for a discussion of the accuracy of this method.</div><h2 class="standard"><a class="sec" name="fcomments" id="fcomments"/>8&#160;&#160;Further Comments</h2>
<div class="paramtext">The time for computing the weights of the discretized data is of order  <m:math><m:mi>n</m:mi></m:math>, while the time for computing the <a class="arg" href="#FFT">FFT</a> is of order <m:math><m:msub><m:mi>n</m:mi><m:mi>s</m:mi></m:msub><m:mrow><m:mi>log</m:mi><m:mfenced separators=""><m:msub><m:mi>n</m:mi><m:mi>s</m:mi></m:msub></m:mfenced></m:mrow></m:math>, as is the time for computing the inverse of the <a class="arg" href="#FFT">FFT</a>.</div><h2 class="standard"><a class="sec" name="example" id="example"/>9&#160;&#160;Example</h2>
<div class="paramtext">A sample of <m:math><m:mn>1000</m:mn></m:math>&#160;standard Normal <m:math><m:mfenced separators=""><m:mn>0</m:mn><m:mo>,</m:mo><m:mn>1</m:mn></m:mfenced></m:math>&#160;variates are generated using <a class="rout" href="../G05/g05skf.xml">G05SKF</a> and the density estimated on <m:math><m:mn>100</m:mn></m:math>&#160;points with a window width of <m:math><m:mn>0.1</m:mn></m:math>.  The resulting estimate of the density function is plotted using <a class="rout" href="../G01/g01agf.xml">G01AGF</a>.</div><h3 class="standard"><a class="sec" name="examtext" id="examtext"/>9.1&#160;&#160;Program Text</h3>
<p><a class="verbatimref" href="../../examples/source/g10bafe.f">Program Text (g10bafe.f)</a></p><h3 class="standard"><a class="sec" name="examdata" id="examdata"/>9.2&#160;&#160;Program Data</h3>
<p><a class="verbatimref" href="../../examples/data/g10bafe.d">Program&#160;Data (g10bafe.d)</a></p><h3 class="standard"><a class="sec" name="examresults" id="examresults"/>9.3&#160;&#160;Program Results</h3>
<p><a class="verbatimref" href="../../examples/baseresults/g10bafe.r">Program Results (g10bafe.r)</a></p>
<hr/><div><a class="rout" href="../../pdf/G10/g10baf.pdf">G10BAF (PDF version)</a></div><div><a class="chap" href="g10conts.xml">G10 Chapter Contents</a></div><div><a class="chapint" href="g10intro.xml">G10 Chapter Introduction</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>
