Sturges's rule[1] is a method to choose the number of bins for a histogram. Given
n
\hat{k}=1+log2(n)
bins in the histogram. This rule is widely employed in data analysis software including Python[2] and R, where it is the default bin selection method.[3]
Sturges's rule comes from the binomial distribution which is used as a discrete approximation to the normal distribution.[4] If the function to be approximated
f
f(y)=\binom{m}{y}py(1-p)m-y
m
p
y=0,1,\ldots,m
p=1/2
f(y)=\binom{m}{y}2-m
2-m
n
n=\sumy\binom{m}{y}=2m
m=log2(n)
k=m+1
Doane[5] proposed modifying Sturges's formula to add extra bins when the data is skewed. Using the method of moments estimator
g1=
m3 | ||||||
|
=
\tfrac{1 | |
n |
n | |
\sum | |
i=1 |
3}{\left[\tfrac{1}{n} | |
(x | |
i-\overline{x}) |
n | |
\sum | |
i=1 |
2 | |
(x | |
i-\overline{x}) |
\right]3/2
2= | |
\sigma | |
g1 |
6(n-2) | |
(n+1)(n+3) |
Doane proposed adding
log2\left(1+
|g1| | ||||
|
\right)
\hat{k}=1+log2(n)+log2\left(1+
|g1| | ||||
|
\right)
|g1|\simeq0
Sturges's rule is not based on any sort of optimisation procedure, like the Freedman–Diaconis rule or Scott's rule. It is simply posited based on the approximation of a normal curve by a binomial distribution. Hyndman has pointed out[6] that any multiple of the binomial coefficients would also converge to a normal distribution, so any number of bins could be obtained following the derivation above. Scott shows that Sturges's rule in general produces oversmoothed histograms i.e. too few bins, and advises against its use in favour of other rules such as Freedman-Diaconis or Scott's rule.