AI Knowledge Tree

Law of large numbers and the central limit theorem

State and use the LLN and CLT to describe the behavior of sample averages.

Averaging many independent measurements does two things: it homes in on the true mean, and its leftover error follows a bell curve no matter what the measurements themselves looked like. The law of large numbers is the first statement; the central limit theorem is the second. Together they justify why sampling works and why Gaussian error models are everywhere.

Setup

Let X1,X2,…X_1, X_2, \dots be independent and identically distributed (i.i.d.) with mean μ=E[Xi]\mu = \mathbb{E}[X_i] and variance σ2=Var⁡(Xi)<∞\sigma^2 = \operatorname{Var}(X_i) < \infty. The sample mean is

Xˉn=1n∑i=1nXi.\bar{X}_n = \frac{1}{n}\sum_{i=1}^n X_i.

Its own mean and variance follow from linearity and independence:

E[Xˉn]=μ,Var⁡(Xˉn)=1n2∑i=1nσ2=σ2n.\mathbb{E}[\bar{X}_n] = \mu, \qquad \operatorname{Var}(\bar{X}_n) = \frac{1}{n^2}\sum_{i=1}^n \sigma^2 = \frac{\sigma^2}{n}.

The mean of the average is the true mean; its variance shrinks like 1/n1/n.

The weak law of large numbers

Theorem. For any ε>0\varepsilon > 0, P(∣Xˉn−μ∣≥ε)→0P(|\bar{X}_n - \mu| \ge \varepsilon) \to 0 as n→∞n \to \infty[1].

Proof. Apply Chebyshev to Xˉn\bar{X}_n, which has mean μ\mu and variance σ2/n\sigma^2/n:

P(∣Xˉn−μ∣≥ε)≤Var⁡(Xˉn)ε2=σ2nε2→n→∞0.P(|\bar{X}_n - \mu| \ge \varepsilon) \le \frac{\operatorname{Var}(\bar{X}_n)}{\varepsilon^2} = \frac{\sigma^2}{n\varepsilon^2} \xrightarrow{n \to \infty} 0.

■\qquad\blacksquare

The sample mean concentrates on μ\mu: for large nn it is within any fixed tolerance with probability approaching 1. This is the formal reason Monte Carlo estimates converge to the quantity they estimate.

The central limit theorem

The LLN says the error Xˉn−μ\bar{X}_n - \mu vanishes; the CLT describes its shape after rescaling so it does not. Since the error has standard deviation σ/n\sigma/\sqrt n, multiply by n/σ\sqrt n / \sigma to keep it order 1.

Theorem. As n→∞n \to \infty[2],

Xˉn−μσ/n=1σn∑i=1n(Xi−μ)  →d  N(0,1),\frac{\bar{X}_n - \mu}{\sigma/\sqrt n} = \frac{1}{\sigma\sqrt n}\sum_{i=1}^n (X_i - \mu) \;\xrightarrow{d}\; \mathcal{N}(0, 1),

where →d\xrightarrow{d} means the CDF converges to that of the standard normal at every point.

The remarkable part is universality: the limit is N(0,1)\mathcal{N}(0,1) regardless of the distribution of the XiX_i, requiring only finite variance. The MGF gives the intuition: the standardized sum's MGF is the nn-th power of a single term's MGF, and (1+t22n+o(1/n))n→et2/2\big(1 + \frac{t^2}{2n} + o(1/n)\big)^n \to e^{t^2/2}, the MGF of the standard normal. A matching MGF means a matching distribution.

Equivalently, for large nn the sample mean is approximately Xˉn≈N(μ,σ2/n)\bar{X}_n \approx \mathcal{N}(\mu, \sigma^2/n). This is the basis of confidence intervals: Xˉn±1.96 σ/n\bar{X}_n \pm 1.96\,\sigma/\sqrt n contains μ\mu about 95% of the time.

Law of large numbers (left): running averages of die rolls converge to the mean 3.5. Central limit theorem (right): standardized means of a skewed exponential are themselves approximately Gaussian.
Law of large numbers (left): running averages of die rolls converge to the mean 3.5. Central limit theorem (right): standardized means of a skewed exponential are themselves approximately Gaussian.

Check it on arrays

python · numpy
import numpy as np

rng = np.random.default_rng(10)

# LLN: running mean of a fair die converges to 3.5
draws = rng.integers(1, 7, size=100_000).astype(float)
running = np.cumsum(draws) / np.arange(1, len(draws) + 1)
for n in [10, 100, 1000, 100_000]:
    print(f"n={n:>6}: running mean {running[n-1]:.4f}  (target 3.5)")

# CLT: standardized sample means of a *skewed* exponential become Gaussian
n, trials = 1000, 200_000
mu, sigma = 1.0, 1.0                       # Exponential(rate=1): mean=var=1
samples = rng.exponential(1.0, size=(trials, n))
means = samples.mean(axis=1)
standardized = (means - mu) / (sigma / np.sqrt(n))
print("standardized sample-mean: mean", round(standardized.mean(), 3),
      "std", round(standardized.std(), 3))
# Fraction within 1.96 should be ~0.95
print("frac within +/-1.96:", round(np.mean(np.abs(standardized) < 1.96), 4))

The running die average settles onto 3.5, and the standardized means of a skewed exponential become a unit normal with ~95% of mass inside ±1.96\pm1.96.

Exercises

Exercise 1. A fair die has mean μ=3.5\mu = 3.5 and variance σ2=35/12≈2.9167\sigma^2 = 35/12 \approx 2.9167. For n=100n = 100 rolls, use Chebyshev's inequality (as in the LLN proof) to bound the probability that the sample mean deviates from 3.53.5 by at least 0.50.5.

Solution

Step 1. The sample mean Xˉ100\bar X_{100} has mean 3.53.5 and variance σ2/n=2.9167/100=0.029167\sigma^2/n = 2.9167/100 = 0.029167.

Step 2. Chebyshev applied to Xˉ100\bar X_{100} with tolerance ε=0.5\varepsilon = 0.5:

P(∣Xˉ100−3.5∣≥0.5)≤Var⁡(Xˉ100)ε2=0.0291670.25=0.116‾.P(|\bar X_{100} - 3.5| \ge 0.5) \le \frac{\operatorname{Var}(\bar X_{100})}{\varepsilon^2} = \frac{0.029167}{0.25} = 0.11\overline{6}.

So the probability is at most about 0.1170.117. This is a loose worst-case bound; the CLT-based normal approximation would give a far smaller actual probability, but Chebyshev needs only the variance.

Exercise 2. The CLT says Xˉn≈N(μ,σ2/n)\bar X_n \approx \mathcal{N}(\mu, \sigma^2/n). Using the standard normal fact P(∣Z∣≤1.96)≈0.95P(|Z| \le 1.96) \approx 0.95, derive the width of a 95% confidence interval for μ\mu and show how it shrinks with nn.

Solution

Step 1. Standardize: Z=(Xˉn−μ)/(σ/n)Z = (\bar X_n - \mu)/(\sigma/\sqrt n) is approximately N(0,1)\mathcal{N}(0, 1), so P(∣Z∣≤1.96)≈0.95P(|Z| \le 1.96) \approx 0.95.

Step 2. Unfold the inequality ∣Xˉn−μ∣≤1.96 σ/n|\bar X_n - \mu| \le 1.96\,\sigma/\sqrt n, which holds with probability about 0.950.95. The interval is Xˉn±1.96 σ/n\bar X_n \pm 1.96\,\sigma/\sqrt n, of full width 2⋅1.96 σ/n=3.92 σ/n2 \cdot 1.96\,\sigma/\sqrt n = 3.92\,\sigma/\sqrt n.

Step 3. The width scales as 1/n1/\sqrt n: to halve it requires four times the data. Quadrupling nn from 100100 to 400400 shrinks the width from 0.392 σ0.392\,\sigma to 0.196 σ0.196\,\sigma.

Exercise 3 (code). Take the most skewed start possible, a Bernoulli(0.10.1) variable. Verify the LLN (running mean converges to 0.10.1) and the CLT (standardized sample means over n=500n = 500 are approximately standard normal, with about 95% of mass within ±1.96\pm 1.96).

Solution
python · numpy
import numpy as np

rng = np.random.default_rng(11)

p = 0.1
mu, sigma = p, np.sqrt(p * (1 - p))    # Bernoulli mean and std

# LLN: running mean of Bernoulli(0.1) converges to 0.1
draws = (rng.random(200_000) < p).astype(float)
running = np.cumsum(draws) / np.arange(1, len(draws) + 1)
assert abs(running[-1] - p) < 0.01

# CLT: standardized means over n=500 are ~ N(0,1)
n, trials = 500, 200_000
samples = (rng.random((trials, n)) < p).astype(float)
means = samples.mean(axis=1)
z = (means - mu) / (sigma / np.sqrt(n))
frac = np.mean(np.abs(z) < 1.96)
assert abs(z.mean()) < 0.02 and abs(z.std() - 1.0) < 0.02
assert abs(frac - 0.95) < 0.01
print("running mean:", round(running[-1], 4), " frac within 1.96:", round(frac, 4))

Even from a sharply skewed Bernoulli, the running mean lands on 0.10.1 and the standardized means form a unit normal with about 95% of mass inside ±1.96\pm 1.96.

With sampling behavior pinned down, the next lesson uses it in reverse: estimating a distribution's parameters from data by maximum likelihood.


References

  1. [1]Wasserman, L. (2004). All of Statistics. Springer. Ch. 5, the law of large numbers and convergence of random variables. doi:10.1007/978-0-387-21736-9↩
  2. [2]Durrett, R. (2019). Probability: Theory and Examples (5th ed.). Cambridge University Press. Ch. 3, the central limit theorem.↩