Consider a sequence of Bernoulli distributed random variables Xi with the same parameter p, and let Sn:=∑i=1nXi be the sum of the first n of them. From the chapter The most important discrete distributions we know that Sn∼Bin(n,p): the sum is binomially distributed. As a reminder, this means the pmf of Sn is p(k)=(kn)pk(1−p)n−k.
For the concrete values n=100,p=0.4, a histogram of 100000 samples looks something like this:
import numpy as np
from scipy.stats import binom, norm
from matplotlib import pyplot as plt
np.random.seed(123123)
binom_samples = binom.rvs(n=100,
p=0.4,
size=100000)
plt.hist(binom_samples, bins=40, density=True)
plt.xlabel("$x$ binomially distributed")
plt.ylabel("Density")
plt.show()
Since large samples always produce this shape, whatever p may be (try it out!), you might suspect that the distribution can be approximated by a function that is easier to compute than the binomial coefficients (kn)=k!(n−k)!n!.
Aside: there is in fact Stirling’s formula for approximating the factorial,
where on the right-hand side the sequence x=xn with
xn=xn(k)=np(1−p)k−np has to be substituted for x. The symbol ∼ means asymptotically equal: the quotient converges to 1.
The approximation is useful because we can now tabulate the function e−2x2 and read off concrete values for any given n,p – considerably more efficient than computing binomial coefficients. The whole observation is known as the theorem of de Moivre–Laplace, and for now it serves as our motivation for examining the function e−2x2 more closely.
To turn the function e−2x2 into a probability density, its integral has to come out as 1. Since it will be very useful later, we compute a slightly more general integral right away:
Since integrals turn up rather often in statistics, it is worth working through this calculation and seeing exactly what happens at each step, and why.
x = np.linspace(20,60,100)
plt.hist(binom_samples, bins=40, density=True)
plt.plot(x, norm(loc=40, scale=np.sqrt(24)).pdf(x), color="red") # expected value n p = 40, variance n p (1-p) = 24
plt.ylabel('Density')
plt.title('Normal density (red) and binomial histogram (blue)')
plt.show()
Standardisation is a special case of a more general statement that you will need all the time:
Two special cases are worth remembering. With a=σ1 and b=−σμ we get the standardisation from above. And conversely: if Z∼N(0,1), then σZ+μ∼N(μ,σ2) – so every normal distribution arises from the standard normal distribution by stretching and shifting. That is exactly how they are generated on a computer, too: mu + sigma * rng.standard_normal(n) needs only one random number generator for all normal distributions. The chapter The multivariate normal distribution takes this as its starting point: there the same construction is carried out with a matrix instead of a number.
We also use the fact that the sum of independent random variables with densities f,g again has a density, namely the convolutionf∗g. Rather than introduce and prove that rigorously, we merely record the result for normal distributions, which can be checked using the convolution.
Even to state this theorem precisely, we need a notion of entropy for continuous distributions. Rather than set that up now, we return to it later, when we also discuss relative entropy, its continuous version and likelihood.
Expected value and variance follow from the rules of calculation in the chapter Expected value and variance; the remarkable part is that the shape is preserved too – the sum is not just some distribution with these moments but a bell curve again. That is far from obvious: the sum of two uniformly distributed variables is triangularly distributed, not uniformly distributed. The normal distribution is said to be stable under convolution. The chapter on the multivariate normal distribution shows the generalisation: there the same holds for dependentX,Y too, as soon as they are jointly normally distributed, with an extra covariance term in the variance.
What matters, though, is the theorem’s take-home message: if nothing is known about a continuous distribution on the real numbers beyond its expected value and variance, the corresponding normal distribution is the most sensible assumption. In this sense the normal distribution is a good continuous substitute for the discrete uniform distribution, but now on all of R (the normal distribution has support R).
The restriction to support R is no formality here; it is the actual modelling assumption. If the support is known more precisely, a different distribution has maximal entropy – and is hence the most sensible assumption:
Support
what else is known
distribution with maximal entropy
{1,…,n}
nothing
discrete uniform distribution, p(k)=n1
[a,b]
nothing
continuous uniform distribution, f(x)=b−a1
[0,∞)
expected value μ
exponential distribution, f(x)=λe−λx with λ=μ1
R
expected value and variance
normal distribution
[a,b]
expected value and variance
truncated normal distribution (scipy.stats.truncnorm)
The profiles of the three continuous distributions are in the chapter The most important continuous distributions, that of the discrete uniform distribution in the chapter The most important discrete distributions. The truncated normal distribution is exactly what it sounds like: a normal distribution whose density is set to 0 outside [a,b] and renormalised inside. You need it when a quantity is bounded by its very nature – proportions between 0 and 1, readings at the display limit of an instrument – and a normal model would otherwise put probability mass where no values can occur at all.
The pattern behind this is always the same: maximal entropy means “assume as little extra as possible”. What you know goes in as a constraint; everything else you leave to chance.
The letter Z is a reminder that ZN is the sum SN=∑i=1NXi we looked at above for Bernoulli variables, normalised to expected value 0 and variance 1.
Convergence in distribution means that the cumulative distribution function of ZN converges to that of a standard normal distribution.
There are also weaker versions of this theorem that allow certain dependencies among the Xi.
Two concrete examples: the error in position fixing with GNSS systems such as GPS is normally distributed (even though the atmospheric disturbances that make the value less accurate are not). In the industrial manufacture of components, likewise, sources of error throughout the production process add up to a normal distribution in the end – one whose variance has to be kept small enough for the component to do its job. A Lego brick, for instance, must not deviate too much from an identically built Lego brick, or the structure will not hold together properly afterwards.
Aside: the speed of the convergence can be estimated too, which tells us how good the approximation by a normal distribution is:
The exact value of C is not known; the bounds given are the current state of research. So for concretely known σ,ρ we can always find an N that makes the left-hand side as small as we like. In other words: for any desired accuracy, we can compute how many of the iid random variables have to be added up (and scaled) for ZN to be approximated by a standard normal distribution.
Naturally, if the expected value is not 0, a variant follows as a corollary (as with the central limit theorem), with convergence to N(μ,1) – and with a different rescaling, to N(μ,σ2) as well. In practice it looks more like this: every unknown error term is modelled by a normal distribution whose expected value and variance are estimated empirically.
Many textbooks, statistics courses and analysis protocols offer a rule of thumb: from N=30 on you may work with a normal distribution. The rule is so widespread that it is rarely questioned – and in that form it is wrong. And Berry–Esseen tells us why.
The bound above reads σ3NCρ. In it, N appears only under a square root; the decisive quantity is the factor ρ/σ3, the third absolute moment relative to the cube of the standard deviation – a measure of how skewed the individual random variable is. For a symmetric distribution this factor is small; for a skewed one it can be arbitrarily large, and then N=30 is simply not enough.
The most important case in practice is a binary feature: “side effect occurred yes/no”, “click yes/no”, “survived yes/no”. Such a feature is Bernoulli distributed with parameter p, and for it we can compute the factor. For X∼Bernoulli(p), centred to have expected value 0,
For a balanced feature, p=0.5, this is exactly 1, and the Berry–Esseen bound at N=30 comes out (with C≈0.44) at 0.44/30≈0.08: the cumulative distribution functions differ by at most eight percentage points – usable. For a rare event, p=0.01, by contrast, the same factor is ≈9.85 and the bound at N=30 becomes
A bound of 0.79 on the deviation between two cumulative distribution functions that both lie between 0 and 1 says nothing at all – it is useless. Only at N=1000 does it drop to ≈0.14. (The Berry–Esseen bound is an upper bound; the actual error may be smaller. But a rule of thumb that cannot even be justified from above is not one you should use.)
So the difference from the N≥30 rule is not academic: for an event that hits one case in a hundred, the correct threshold is 33 times higher. That is exactly the situation with rare side effects in medical studies.
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4))
for ax, n in ((ax1, 30), (ax2, 1000)):
p = 0.01
k = np.arange(0, int(n * p + 4 * np.sqrt(n * p * (1 - p))) + 2)
ax.bar(k, binom(n, p).pmf(k), label="Binomial distribution", alpha=0.7)
xs = np.linspace(k.min() - 1, k.max(), 200)
ax.plot(xs, norm(loc=n * p, scale=np.sqrt(n * p * (1 - p))).pdf(xs),
color="black", label="Normal approximation")
np_text = f"{n * p:g}"
ax.set_title(f"$N = {n}$, $p = 0.01$ ($Np = {np_text}$)")
ax.set_xlabel("Number of successes")
ax.legend()
plt.show()
On the left, at N=30, almost all the probability mass sits on the values 0 and 1 – the distribution is cut off at zero and heavily skewed to the right, while the normal approximation runs placidly off into negative territory and spreads probability where there are no outcomes at all. On the right, at N=1000, the Laplace condition is just satisfied, with Np=10, and the bell shape is recognisable.
The moral is more general than the example: a rule of thumb that names only the sample size and says nothing about the distribution cannot work. What counts is the ratio of skewness to sample size.