nclass           package:grDevices           R Documentation(latin1)

Compute the Number of Classes for a Histogram

Description:

     Compute the number of classes for a histogram.

Usage:

     nclass.Sturges(x)
     nclass.scott(x)
     nclass.FD(x)

Arguments:

       x: A data vector. 

Details:

     'nclass.Sturges' uses Sturges' formula, implicitly basing bin
     sizes on the range of the data.

     '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 '1'.

     'nclass.FD' uses the Freedman-Diaconis choice based on the
     inter-quartile range ('IQR') unless that's zero where it reverts
     to 'mad(x, constant=2)' and when that is 0 as well, returns '1'.

Value:

     The suggested number of classes.

References:

     Venables, W. N. and Ripley, B. D. (2002) _Modern Applied
     Statistics with S-PLUS._ Springer, page 112.

     Freedman, D. and Diaconis, P. (1981) On the histogram as a density
     estimator: L_2 theory. _Zeitschrift fuer
     Wahrscheinlichkeitstheorie und verwandte Gebiete_ *57*, 453-476.

     Scott, D. W. (1979) On optimal and data-based histograms.
     _Biometrika_ *66*, 605-610.

     Scott, D. W. (1992) _Multivariate Density Estimation. Theory,
     Practice, and Visualization_. Wiley.

See Also:

     'hist' and 'truehist' (which use a different default).

Examples:

     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

