\HeaderA{bandwidth}{Bandwidth Selectors for Kernel Density Estimation}{bandwidth}
\aliasA{bw.bcv}{bandwidth}{bw.bcv}
\aliasA{bw.nrd}{bandwidth}{bw.nrd}
\aliasA{bw.nrd0}{bandwidth}{bw.nrd0}
\aliasA{bw.SJ}{bandwidth}{bw.SJ}
\aliasA{bw.ucv}{bandwidth}{bw.ucv}
\keyword{distribution}{bandwidth}
\keyword{smooth}{bandwidth}
\begin{Description}\relax
Bandwidth selectors for gaussian windows in \code{\LinkA{density}{density}}.
\end{Description}
\begin{Usage}
\begin{verbatim}
bw.nrd0(x)

bw.nrd(x)

bw.ucv(x, nb = 1000, lower = 0.1 * hmax, upper = hmax)

bw.bcv(x, nb = 1000, lower = 0.1 * hmax, upper = hmax)

bw.SJ(x, nb = 1000, lower = 0.1 * hmax, upper = hmax,
      method = c("ste", "dpi"))
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] A data vector.
\item[\code{nb}] number of bins to use.
\item[\code{lower, upper}] Range over which to minimize.  The default is
almost always satisfactory.  \code{hmax} is calculated internally
from a normal reference bandwidth.
\item[\code{method}] Either \code{"ste"} ("solve-the-equation") or
\code{"dpi"} ("direct plug-in").
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{bw.nrd0} implements a rule-of-thumb for
choosing the bandwidth of a Gaussian kernel density estimator.
It defaults to 0.9 times the
minimum of the standard deviation and the interquartile range divided by
1.34 times the sample size to the negative one-fifth power
(= Silverman's \sQuote{rule of thumb}, Silverman (1986, page 48, eqn (3.31))
\emph{unless} the quartiles coincide when a positive result
will be guaranteed.

\code{bw.nrd} is the more common variation given by Scott (1992),
using factor 1.06.

\code{bw.ucv} and \code{bw.bcv} implement unbiased and
biased cross-validation respectively.

\code{bw.SJ} implements the methods of Sheather \& Jones (1991)
to select the bandwidth using pilot estimation of derivatives.\\
The algorithm solves an equation (via \code{\LinkA{uniroot}{uniroot}}) and
because of that, enlarges the interval \code{c(lower,upper)} when
the boundaries were not user-specified and do not bracket the root.
\end{Details}
\begin{Value}
A bandwidth on a scale suitable for the \code{bw} argument
of \code{density}.
\end{Value}
\begin{References}\relax
Scott, D. W. (1992)
\emph{Multivariate Density Estimation: Theory, Practice, and
Visualization.}
Wiley.

Sheather, S. J. and Jones, M. C. (1991)
A reliable data-based bandwidth selection method for kernel density
estimation.
\emph{Journal of the Royal Statistical Society series B},
\bold{53}, 683--690.

Silverman, B. W. (1986)
\emph{Density Estimation}.
London: Chapman and Hall.

Venables, W. N. and Ripley, B. D. (2002)
\emph{Modern Applied Statistics with S}.
Springer.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{density}{density}}.

\code{\LinkA{bandwidth.nrd}{bandwidth.nrd}}, \code{\LinkA{ucv}{ucv}},
\code{\LinkA{bcv}{bcv}} and \code{\LinkA{width.SJ}{width.SJ}} in
package \pkg{MASS}, which are all scaled to the \code{width} argument
of \code{density} and so give answers four times as large.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(graphics)

plot(density(precip, n = 1000))
rug(precip)
lines(density(precip, bw="nrd"), col = 2)
lines(density(precip, bw="ucv"), col = 3)
lines(density(precip, bw="bcv"), col = 4)
lines(density(precip, bw="SJ-ste"), col = 5)
lines(density(precip, bw="SJ-dpi"), col = 6)
legend(55, 0.035,
       legend = c("nrd0", "nrd", "ucv", "bcv", "SJ-ste", "SJ-dpi"),
       col = 1:6, lty = 1)
\end{ExampleCode}
\end{Examples}

