The CLT for Bernoulli Trials
The law of large numbers says that the proportion of successes in trials approaches . The central limit theorem says much more: it tells us the shape of the fluctuations around , and that shape is always the normal curve. The first version, for coin tossing, was found by de Moivre in 1733 and extended by Laplace.
Standardizing the binomial
Let be the number of successes in Bernoulli trials with probability . It has mean and standard deviation . The standardized sum
has mean 0 and standard deviation 1 for every . The de Moivre–Laplace theorem states that for large ,
The histogram of approaches the standard normal density, whatever is (though the approach is slower when is near 0 or 1).
from math import comb, sqrt, exp, pi
n, p = 100, 0.3
q = 1 - p
mu, sd = n * p, sqrt(n * p * q)
print(" k binomial normal approx")
for k in range(20, 41, 2):
b = comb(n, k) * p ** k * q ** (n - k)
z = (k - mu) / sd
approx = exp(-z * z / 2) / sqrt(2 * pi) / sd # density at z, scaled to one unit of k
print(f"{k:2d} {b:.5f} {approx:.5f}") k binomial normal approx
20 0.00758 0.00805
22 0.01903 0.01897
24 0.03804 0.03694
26 0.06127 0.05948
28 0.08041 0.07915
30 0.08678 0.08706
32 0.07761 0.07915
34 0.05788 0.05948
36 0.03620 0.03694
38 0.01907 0.01897
40 0.00849 0.00805
Each binomial probability is close to the normal density at the standardized point, divided by (the width of one unit of in standardized units).
The continuity correction
takes integer values, while the normal is continuous. To approximate , use : the bar for the value extends to . This half-unit correction noticeably improves accuracy for moderate .
from math import comb, sqrt, erf
Phi = lambda z: 0.5 * (1 + erf(z / sqrt(2)))
n, p = 50, 0.4
mu, sd = n * p, sqrt(n * p * (1 - p))
for k in [15, 20, 25]:
exact = sum(comb(n, j) * p ** j * (1 - p) ** (n - j) for j in range(k + 1))
plain = Phi((k - mu) / sd)
corrected = Phi((k + 0.5 - mu) / sd)
print(f"P(S <= {k}): exact {exact:.4f} normal {plain:.4f} with correction {corrected:.4f}")P(S <= 15): exact 0.0955 normal 0.0745 with correction 0.0970
P(S <= 20): exact 0.5610 normal 0.5000 with correction 0.5574
P(S <= 25): exact 0.9427 normal 0.9255 with correction 0.9438
How far from ?
In 10,000 tosses of a fair coin, . So the number of heads lies between 4900 and 5100 with probability about 95% (two standard deviations), and outside 4850–5150 with probability about 0.3%. Getting 5200 heads would be a 4-standard-deviation event, probability about : strong evidence of a biased coin.
import numpy as np
rng = np.random.default_rng(1)
heads = rng.binomial(10_000, 0.5, 200_000)
print("P(4900 <= S <= 5100) ~", round(((heads >= 4900) & (heads <= 5100)).mean(), 4))
print("P(|S - 5000| > 150) ~", round((np.abs(heads - 5000) > 150).mean(), 4))
print("largest |S - 5000| in 200,000 experiments:", int(np.abs(heads - 5000).max()))P(4900 <= S <= 5100) ~ 0.9557
P(|S - 5000| > 150) ~ 0.0028
largest |S - 5000| in 200,000 experiments: 222
Proportions
Dividing by : the proportion is approximately normal with mean and standard deviation . This is the basis of polls and A/B tests: with 1000 respondents, a 50% proportion is estimated within about percentage points, 95% of the time. The Statistics course builds confidence intervals from this.
In software
A/B testing dashboards compute z-scores of conversion rates exactly this way. Quality monitoring flags a batch whose defect count is more than 3 standard deviations from the expected . Load testing tools use the normal approximation to say how many requests are needed before an error rate can be measured to a given precision.
Exercises
Exercise 1: Dice sixes
Roll a die 600 times. Approximate the probability of between 90 and 110 sixes (inclusive), with the continuity correction.
Answer
About 0.75.
Solution
, . Using the range 89.5 to 110.5 gives , and . Without the correction, gives only about 0.73.
Exercise 2: A poll
A poll of 2500 people finds 52% support. How many standard deviations is this from 50%, assuming true support is 50%?
Answer
2 standard deviations.
Solution
, so is standard deviations above .
Exercise 3: Exact versus approximate (code)
Compute the exact binomial probability for Exercise 1 and both normal approximations.
Answer
Exact 0.7501; the corrected approximation (0.7499) is much closer than the plain one (0.7267).
Solution
from math import comb, sqrt, erf
Phi = lambda z: 0.5 * (1 + erf(z / sqrt(2)))
n, p = 600, 1 / 6
mu, sd = n * p, sqrt(n * p * (1 - p))
exact = sum(comb(n, k) * p ** k * (1 - p) ** (n - k) for k in range(90, 111))
print(round(exact, 4), round(Phi((110 - mu) / sd) - Phi((90 - mu) / sd), 4),
round(Phi((110.5 - mu) / sd) - Phi((89.5 - mu) / sd), 4))0.7501 0.7267 0.7499
Test yourself
In 10,000 fair coin tosses, the standard deviation of the number of heads is…
- 5000
- 100
- 50
- 2500
Why add 0.5 in the continuity correction?
- To make the mean larger
- Because each integer value's bar extends half a unit on each side
- To fix rounding errors in Python
- It is always 0.5 for any distribution