Rule for choosing histogram bins
Scott's rule is a method to select the number of bins in a histogram. Scott's rule is widely employed in data analysis software including R, Python and Microsoft Excel where it is the default bin selection method.
For a set of formula_1 observations formula_2 let formula_3 be the histogram approximation of some function formula_4. The integrated mean squared error (IMSE) is
formula_5
Where formula_6 denotes the expectation across many independent draws of formula_1 data points. By Taylor expanding to first order in formula_8, the bin width, Scott showed that the optimal width is
formula_9
This formula is also the basis for the Freedman–Diaconis rule.
By taking a "normal reference" i.e. assuming that formula_4 is a normal distribution, the equation for formula_11 becomes
formula_12
where formula_13 is the standard deviation of the normal distribution and is estimated from the data. With this value of bin width Scott demonstrates that
formula_14
showing how quickly the histogram approximation approaches the true distribution as the number of samples increases.
Terrell–Scott rule.
Another approach developed by Terrell and Scott is based on the observation that, among all densities formula_15 defined on a compact interval, say formula_16, with derivatives which are absolutely continuous, the density which minimises formula_17 is
formula_18
Using this with formula_19 in the expression for formula_11 gives an upper bound on the value of bin width which is
formula_21
So, for functions satisfying the continuity conditions, at least
formula_22
bins should be used.
This rule is also called the "oversmoothed rule" or the "Rice rule", so called because both authors worked at Rice University. The Rice rule is often reported with the factor of 2 outside the cube root, formula_23, and may be considered a different rule. The key difference from Scott's rule is that this rule does not assume the data is normally distributed and the bin width only depends on the number of samples, not on any properties of the data.
In general formula_24 is not an integer so formula_25 is used where formula_26 denotes the ceiling function.
References.
 ;templatestyles src="Reflist/styles.css" / ;