\inputencoding{latin1}
\HeaderA{nclass}{Compute the Number of Classes for a Histogram}{nclass}
\methaliasA{nclass.FD}{nclass}{nclass.FD}
\methaliasA{nclass.scott}{nclass}{nclass.scott}
\methaliasA{nclass.Sturges}{nclass}{nclass.Sturges}
\keyword{univar}{nclass}
\begin{Description}\relax
Compute the number of classes for a histogram.
\end{Description}
\begin{Usage}
\begin{verbatim}
nclass.Sturges(x)
nclass.scott(x)
nclass.FD(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] A data vector.

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{nclass.Sturges} uses Sturges' formula, implicitly basing bin
sizes on the range of the data.

\code{nclass.scott} uses Scott's choice for a normal distribution based on
the estimate of the standard error, unless that is zero where it
returns \code{1}.

\code{nclass.FD} uses the Freedman-Diaconis choice based on the
inter-quartile range (\code{\LinkA{IQR}{IQR}}) unless that's zero where it
reverts to \code{\LinkA{mad}{mad}(x, constant=2)} and when that is \eqn{0}{}
as well, returns \code{1}.
\end{Details}
\begin{Value}
The suggested number of classes.
\end{Value}
\begin{References}\relax
Venables, W. N. and Ripley, B. D. (2002)
\emph{Modern Applied Statistics with S-PLUS.}
Springer, page 112.

Freedman, D. and Diaconis, P. (1981)
On the histogram as a density estimator: \eqn{L_2}{} theory.
\emph{Zeitschrift für Wahrscheinlichkeitstheorie
und verwandte Gebiete} \bold{57}, 453--476.

Scott, D. W. (1979) On optimal and data-based histograms.
\emph{Biometrika} \bold{66}, 605--610.

Scott, D. W. (1992)
\emph{Multivariate Density Estimation. Theory, Practice, and
Visualization}. Wiley.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{hist}{hist}} and \code{\LinkA{truehist}{truehist}} (which use
a different default).
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
set.seed(1)
x <- stats::rnorm(1111)
nclass.Sturges(x)

## Compare them:
NC <- function(x) c(Sturges = nclass.Sturges(x),
      Scott = nclass.scott(x), FD = nclass.FD(x))
NC(x)
onePt <- rep(1, 11)
NC(onePt) # no longer gives NaN
\end{ExampleCode}
\end{Examples}

