n.bins {car} | R Documentation |
Several rules for calculating the number of bins to use for a histogram.
n.bins(x, rule=c("freedman.diaconis", "sturges", "scott", "simple"))
x |
numeric vector, variable for histogram |
rule |
see below. |
"freedman.diaconis"
:"sturges"
:"scott"
:"simple"
:
where n is the number of observations, range is the range of x
,
IQR is the inter-quartile range of x
, and s is the standard
deviation of x
.
the number of bins.
John Fox jfox@mcmaster.ca
Freedman, D. and Diaconis, P. (1981) On the histogram as a density estimator. Zeitschrift fur Wahrscheinlichkeitstheorie und verwandte Gebiete 57, 453–476.
Scott, D. W. (1979) On optimal and data based-histograms. Biometrika 66, 605–610.
Venables, W. N. and Ripley, B. D. (1999) Modern Applied Statistics with S-PLUS, Third Edition, Springer.
attach(UN) n.bins(gdp) ## [1] 19 n.bins(gdp, "sturges") ## [1] 9 n.bins(gdp, "scott") ## [1] 8 n.bins(gdp, "simple") ## [1] 22 hist(gdp) hist(gdp, nclass=n.bins(gdp))