nclass
Compute the Number of Classes for a Histogram
Description
Computes the number of bins for a histogram.
- nclass.FD uses the Freedman-Diaconis method.
- scott uses the Scott method.
- nclass.Sturges uses the Sturges method.
Usage
nclass.FD(x)
nclass.scott(x)
nclass.Sturges(x)
Arguments
x |
a numeric vector. NAs are allowed.
|
Details
- For nclass.FD, the histogram bandwidth is given by 2*IQR*n^(-1/3),
where n is the length of x, and IQR is the interquartile range
of x.
If IQR is zero and mad(x) is nonzero, then the mad
value is used instead of the IQR.
- For nclass.scott, the histogram bandwidth is given by 3.5*S*n^(1/3),
where S is square root of variance of x.
Then the number of bins is computed as the difference in the range of
x divided by the bandwidth.
If the bandwidth is non-positive, the number of bins is set to 1.
- For nclass.Sturges, the number of bins is given by 1+log2(n).
These functions are based on the nclass functions
described in Venables and Ripley (1999).
Value
returns the number of bins. If bandwidth is negative or zero, the number of bins is 1.
References
Venables, W. N. and Ripley, B. D. 1999. Modern Applied Statistics with S-PLUS. Third Editiion. New York, NY: Springer.
See Also
hist
Examples
PetalWidth <- Sdatasets::iris$Petal.Width)
nclass.FD(PetalWidth)
nclass.scott(PetalWidth)
nclass.Sturges(PetalWidth)