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 n {\displaystyle n} observations x i {\displaystyle x_{i}} let f ^ ( x ) {\displaystyle {\hat {f}}(x)} be the histogram approximation of some function f ( x ) {\displaystyle f(x)} . The integrated mean squared error (IMSE) is
IMSE = E [ ∫ − ∞ ∞ d x ( f ^ ( x ) − f ( x ) ) 2 ] {\displaystyle {\text{IMSE}}=E\left[\int _{-\infty }^{\infty }dx({\hat {f}}(x)-f(x))^{2}\right]}
Where E [ ⋅ ] {\displaystyle E[\cdot ]} denotes the expectation across many independent draws of n {\displaystyle n} data points. By Taylor expanding to first order in h {\displaystyle h} , the bin width, Scott showed that the optimal width is
h ∗ = ( 6 / ∫ − ∞ ∞ f ′ ( x ) 2 d x ) 1 / 3 n − 1 / 3 {\displaystyle h^{*}=\left(6/\int _{-\infty }^{\infty }f'(x)^{2}dx\right)^{1/3}n^{-1/3}}
This formula is also the basis for the Freedman–Diaconis rule. By taking a normal reference i.e. assuming that f ( x ) {\displaystyle f(x)} is a normal distribution, the equation for h ∗ {\displaystyle h^{*}} becomes
h ∗ = ( 24 π ) 1 / 3 σ n − 1 / 3 ∼ 3.5 σ n − 1 / 3 {\displaystyle h^{*}=\left(24{\sqrt {\pi }}\right)^{1/3}\sigma n^{-1/3}\sim 3.5\sigma n^{-1/3}}
where σ {\displaystyle \sigma } is the standard deviation of the normal distribution and is estimated from the data. With this value of bin width Scott demonstrates that
IMSE ∝ n − 2 / 3 {\displaystyle {\text{IMSE}}\propto n^{-2/3}}
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 g ( x ) {\displaystyle g(x)} defined on a compact interval, say | x | < 1 / 2 {\displaystyle |x|<1/2} , with derivatives which are absolutely continuous, the density which minimises ∫ ∞ ∞ d x ( g ( k ) ( x ) ) 2 {\displaystyle \int _{\infty }^{\infty }dx(g^{(k)}(x))^{2}} is
… excerpt ends here. Continue reading the full article.

