Skip to contents

Computes the optimal number of classes/bins for an histogram as the maximum between the Sturges and Freedman-Diaconis (FD) estimators. For small datasets the Sturges value will usually be chosen, while larger datasets will usually default to FD. Avoids the overly conservative behaviour of FD and Sturges for small and large datasets, respectively. This is the default option in numpy.histogram_bin_edges available in Python.

Usage

nclass.hist(x, ...)

Arguments

x

a vector of data values.

...

additional arguments to be passed to low level functions.

Value

The value of suggested number of classes/bins.

Author

Luca Scrucca

Examples

set.seed(1)
x <- stats::rnorm(111)
nclass.hist(x)
#> [1] 9
x <- stats::rnorm(1111)
nclass.hist(x)
#> [1] 26