Sturges's rule

Sturges's rule is a method to choose the number of bins for a histogram. Given $$n$$ observations, Sturges's rule suggests using



\hat{k} = 1 + \log_2(n) $$

bins in the histogram. This rule is widely employed in data analysis software including Python and R, where it is the default bin selection method.

Sturges's rule comes from the binomial distribution which is used as a discrete approximation to the normal distribution. If the function to be approximated $$f$$ is binomially distributed then

f(y) = \binom{m}{y} p^y (1-p)^{m-y} $$ where $$m$$ is the number of trials and $$p$$ is the probability of success and $$y = 0,1,\ldots,m$$. Choosing $$p=1/2$$ gives

f(y) = \binom{m}{y} 2^{-m} $$ In this form we can consider $$2^{-m}$$ as the normalisation factor and Sturges's rule is saying that the sample should result in a histogram with bin counts given by the binomial coefficients. Since the total sample size is fixed to $$n$$ we must have

n = \sum_y \binom{m}{y} = 2^m $$ using the well-known formula for sums of the binomial coefficients. Solving this by taking logs of both sides gives $$m = \log_2(n)$$ and finally using $$k = m+1$$ (due to counting the 0 outcomes) gives Sturges's rule. In general Sturges's rule does not give an integer answer so the result is rounded up.

Doane's formula
Doane proposed modifying Sturges's formula to add extra bins when the data is skewed. Using the method of moments estimator

g_1 = \frac{m_3}{m_2^{3/2}} = \frac{\tfrac{1}{n} \sum_{i=1}^n (x_i-\overline{x})^3}{\left[\tfrac{1}{n} \sum_{i=1}^n (x_i-\overline{x})^2 \right]^{3/2}}, $$ along with its variance
 * $$ \sigma_{g_1}^2= \frac { 6(n-2) }{ (n+1)(n+3) }$$

Doane proposed adding $$ \log_2 \left( 1 + \frac { |g_1| }{\sigma_{g_1}} \right) $$ extra bins giving Doane's formula

\hat{k} = 1 + \log_2(n) + \log_2 \left( 1 + \frac { |g_1| }{\sigma_{g_1}} \right) $$ For symmetric distributions $$|g_1| \simeq 0$$ this is equivalent to Sturges's rule. For asymmetric distributions a number of additional bins will be used.

Criticisms


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 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.