\Header{dpih}{Select a Histogram Bin Width}
\keyword{smooth}{dpih}
\begin{Description}\relax
Uses direct plug-in methodology to select the bin width of 
a histogram.\end{Description}
\begin{Usage}
\begin{verbatim}
dpih(x, scalest="minim", level=2, gridsize=401, 
     range.x=range(x), truncate=TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] vector containing the sample on which the
histogram is to be constructed.

\item[\code{scalest}] estimate of scale.

\code{"stdev"} - standard deviation is used.

\code{"iqr"} - inter-quartile range divided by 1.349 is used.

\code{"minim"} - minimum of \code{"stdev"} and \code{"iqr"} is used.

\item[\code{level}] number of levels of functional estimation used in the
plug-in rule.

\item[\code{gridsize}] number of grid points used in the binned approximations
to functional estimates.

\item[\code{range.x}] range over which functional estimates are obtained.
The default is the minimum and maximum data values.

\item[\code{truncate}] if \code{truncate} is \code{TRUE} then observations outside
of the interval specified by \code{range.x} are omitted.
Otherwise, they are used to weight the extreme grid points.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The direct plug-in approach, where unknown functionals
that appear in expressions for the asymptotically
optimal bin width and bandwidths
are replaced by kernel estimates, is used.
The normal distribution is used to provide an
initial estimate.\end{Details}
\begin{Value}
the selected bin width.\end{Value}
\begin{Section}{Background}
This method for selecting the bin width of a histogram is
described in Wand (1995). It is an extension of the
normal scale rule of Scott (1979) and uses plug-in ideas
from bandwidth selection for kernel density estimation
(e.g. Sheather and Jones, 1991).\end{Section}
\begin{References}\relax
Scott, D. W. (1979). 
On optimal and data-based histograms.
\emph{Biometrika},
\bold{66}, 605--610.

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. 

Wand, M. P. (1995).
Data-based choice of histogram binwidth.
\emph{University of New South Wales},
Australian Graduate School of Management 
Working Paper Series No. 95--011.\end{References}
\begin{SeeAlso}\relax
\code{\Link{hist}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(geyser, package="MASS")
x <- geyser$duration
h <- dpih(x)
bins <- seq(min(x)-0.1, max(x)+0.1+h, by=h)
hist(x, breaks=bins)
\end{ExampleCode}
\end{Examples}

