Sturges's rule is a method to choose the number of bins for a histogram. Given n {\displaystyle n} observations, Sturges's rule suggests using
k ^ = 1 + log 2 ( n ) {\displaystyle {\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 {\displaystyle f} is binomially distributed then
f ( y ) = ( m y ) p y ( 1 − p ) m − y {\displaystyle f(y)={\binom {m}{y}}p^{y}(1-p)^{m-y}}
where m {\displaystyle m} is the number of trials and p {\displaystyle p} is the probability of success and y = 0 , 1 , … , m {\displaystyle y=0,1,\ldots ,m} . Choosing p = 1 / 2 {\displaystyle p=1/2} gives
f ( y ) = ( m y ) 2 − m {\displaystyle f(y)={\binom {m}{y}}2^{-m}}
In this form we can consider 2 − m {\displaystyle 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 {\displaystyle n} we must have
n = ∑ y ( m y ) = 2 m {\displaystyle 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 ) {\displaystyle m=\log _{2}(n)} and finally using k = m + 1 {\displaystyle 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 are skewed. Using the method of moments estimator
g 1 = m 3 m 2 3 / 2 = 1 n ∑ i = 1 n ( x i − x ¯ ) 3 [ 1 n ∑ i = 1 n ( x i − x ¯ ) 2 ] 3 / 2 , {\displaystyle 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
… excerpt ends here. Continue reading the full article.

