TExcelTAD
Home › Probability Theory › The CLT for Bernoulli Trials

The CLT for Bernoulli Trials

The law of large numbers says that the proportion of successes in nn trials approaches pp. The central limit theorem says much more: it tells us the shape of the fluctuations around pp, 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 SnS_n be the number of successes in nn Bernoulli trials with probability pp. It has mean npnp and standard deviation npq\sqrt{npq}. The standardized sum

Sn∗=Sn−npnpqS_n^* = \frac{S_n - np}{\sqrt{npq}}

has mean 0 and standard deviation 1 for every nn. The de Moivre–Laplace theorem states that for large nn,

Pr⁡[a≤Sn∗≤b]≈Φ(b)−Φ(a)=∫ab12πe−x2/2 dx\Pr[a \le S_n^* \le b] \approx \Phi(b) - \Phi(a) = \int_a^b \frac{1}{\sqrt{2\pi}} e^{-x^2/2}\,dx

The histogram of Sn∗S_n^* approaches the standard normal density, whatever pp is (though the approach is slower when pp is near 0 or 1).

python · try it yourself
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 σ\sigma (the width of one unit of kk in standardized units).

The continuity correction

SnS_n takes integer values, while the normal is continuous. To approximate Pr⁡[Sn≤k]\Pr[S_n \le k], use Φ(k+0.5−npnpq)\Phi\left(\frac{k + 0.5 - np}{\sqrt{npq}}\right): the bar for the value kk extends to k+0.5k + 0.5. This half-unit correction noticeably improves accuracy for moderate nn.

python · try it yourself
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 n/2n/2?

In 10,000 tosses of a fair coin, σ=10000⋅14=50\sigma = \sqrt{10000 \cdot \frac{1}{4}} = 50. 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 6×10−56 \times 10^{-5}: strong evidence of a biased coin.

python · try it yourself
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 nn: the proportion p^=Sn/n\hat{p} = S_n/n is approximately normal with mean pp and standard deviation pq/n\sqrt{pq/n}. This is the basis of polls and A/B tests: with 1000 respondents, a 50% proportion is estimated within about 20.25/1000≈3.22\sqrt{0.25/1000} \approx 3.2 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 npnp. 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

μ=100\mu = 100, σ=600⋅16⋅56≈9.13\sigma = \sqrt{600 \cdot \frac{1}{6} \cdot \frac{5}{6}} \approx 9.13. Using the range 89.5 to 110.5 gives z=±1.15z = \pm 1.15, and Φ(1.15)−Φ(−1.15)≈0.75\Phi(1.15) - \Phi(-1.15) \approx 0.75. Without the correction, z=±1.095z = \pm 1.095 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

0.25/2500=0.01\sqrt{0.25/2500} = 0.01, so 0.520.52 is 22 standard deviations above 0.500.50.

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
python · try it yourself
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…

  1. 5000
  2. 100
  3. 50
  4. 2500

Why add 0.5 in the continuity correction?

  1. To make the mean larger
  2. Because each integer value's bar extends half a unit on each side
  3. To fix rounding errors in Python
  4. It is always 0.5 for any distribution