Last data update: 2014.03.03

R: Optimal Number Of Bins
OptimalNoBinsR Documentation

Optimal Number Of Bins

Description

Calculation of the optimal number of bins for a histogram.

Usage

OptimalNoBins(Data)

Arguments

Data

Data

Details

The bin width ist defined with bw=3.49*stdrobust(1/(n)^1/3)

Value

optNrOfBins

The best possible number of bins. Not less than 10 though

Note

OptimalNoBins() is a kernel density estimation for fixed intervals.

Author(s)

Alfred Ultsch, Michael Thrun

References

David W. Scott Jerome P. Keating: A Primer on Density Estimation for the Great Home Run Race of 98, STATS 25, 1999, pp 16-22.

See Also

ParetoRadius

Examples

 
 Data = c(rnorm(1000),rnorm(2000)+2,rnorm(1000)*2-1)
 optNrOfBins = OptimalNoBins(Data)
 minData = min(Data,na.rm = TRUE)
 maxData = max(Data,na.rm = TRUE)
 i = maxData-minData
 optBreaks = seq(minData, maxData, i/optNrOfBins) # bins in fixed intervals
 hist(Data, breaks=optBreaks)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(AdaptGauss)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/AdaptGauss/OptimalNoBins.Rd_%03d_medium.png", width=480, height=480)
> ### Name: OptimalNoBins
> ### Title: Optimal Number Of Bins
> ### Aliases: OptimalNoBins
> ### Keywords: histogram bins kernel density estimation
> 
> ### ** Examples
>  
>  Data = c(rnorm(1000),rnorm(2000)+2,rnorm(1000)*2-1)
>  optNrOfBins = OptimalNoBins(Data)
>  minData = min(Data,na.rm = TRUE)
>  maxData = max(Data,na.rm = TRUE)
>  i = maxData-minData
>  optBreaks = seq(minData, maxData, i/optNrOfBins) # bins in fixed intervals
>  hist(Data, breaks=optBreaks)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>