TExcelTAD
Home › Probability Theory › The Law of Large Numbers

The Law of Large Numbers

Why does the proportion of heads approach 1/21/2? Why can casinos plan on their profits and insurers on their claims? The law of large numbers is the theorem that connects probability to long-run frequency: averages of many independent trials settle near the expected value.

The weak law

Let X1,X2,…X_1, X_2, \ldots be independent with the same distribution, mean μ\mu and finite variance σ2\sigma^2, and let Xˉn=1n(X1+⋯+Xn)\bar{X}_n = \frac{1}{n}(X_1 + \cdots + X_n). For every ε>0\varepsilon > 0:

Pr⁡[∣Xˉn−μ∣≥ε]  ⟶  0as n→∞\Pr\big[\lvert \bar{X}_n - \mu \rvert \ge \varepsilon\big] \;\longrightarrow\; 0 \quad \text{as } n \to \infty

Proof. E[Xˉn]=μE[\bar{X}_n] = \mu and Var⁡(Xˉn)=σ2/n\operatorname{Var}(\bar{X}_n) = \sigma^2/n (Variance). By Chebyshev's inequality,

Pr⁡[∣Xˉn−μ∣≥ε]≤σ2nε2→0\Pr\big[\lvert \bar{X}_n - \mu \rvert \ge \varepsilon\big] \le \frac{\sigma^2}{n\varepsilon^2} \to 0

That is the whole proof: the variance of the average shrinks like 1/n1/n.

python · try it yourself
import numpy as np

rng = np.random.default_rng(2)
eps = 0.1
for n in [10, 100, 1000, 10_000]:
    avgs = rng.integers(1, 7, size=(5000, n)).mean(axis=1)
    freq = np.mean(np.abs(avgs - 3.5) >= eps)
    bound = (35 / 12) / (n * eps ** 2)
    print(f"n={n:6d}  P(|avg - 3.5| >= {eps}) ~ {freq:.4f}   Chebyshev bound {min(bound, 1):.4f}")
n=    10  P(|avg - 3.5| >= 0.1) ~ 0.9274   Chebyshev bound 1.0000
n=   100  P(|avg - 3.5| >= 0.1) ~ 0.5860   Chebyshev bound 1.0000
n=  1000  P(|avg - 3.5| >= 0.1) ~ 0.0688   Chebyshev bound 0.2917
n= 10000  P(|avg - 3.5| >= 0.1) ~ 0.0000   Chebyshev bound 0.0292

What the law does and does not say

  • It is about the average, not the sum. The sum Sn=nXˉnS_n = n\bar{X}_n drifts from nμn\mu by about σn\sigma\sqrt{n}, which grows. After a run of bad luck, the average recovers because later outcomes swamp the early ones, not because luck "balances out". The coin has no memory (Simulating Chance).
  • It needs a finite mean. For Cauchy samples, averages do not converge.
  • The strong law says more: with probability 1, the sequence of averages actually converges to μ\mu. The weak law only says that for each large nn, a big deviation is unlikely.

The gambler's fallacy, simulated

After 10 tails in a row, the next toss is still heads with probability 1/21/2, yet the long-run proportion still goes to 1/21/2. Both are true at once:

python · try it yourself
import random

rng = random.Random(5)
after_streak = heads_after = 0
streak = 0
tosses = [rng.random() < 0.5 for _ in range(2_000_000)]
for i in range(len(tosses) - 1):
    streak = streak + 1 if not tosses[i] else 0
    if streak >= 6:
        after_streak += 1
        heads_after += tosses[i + 1]
print("tosses following 6+ tails in a row:", after_streak)
print("fraction of heads among them:", round(heads_after / after_streak, 4))
print("overall fraction of heads:", round(sum(tosses) / len(tosses), 4))
tosses following 6+ tails in a row: 31005
fraction of heads among them: 0.5036
overall fraction of heads: 0.5005

Monte Carlo rests on it

Every simulation estimate in this course is an average of independent trials, so the law of large numbers guarantees that it converges, and Chebyshev (or better, the CLT) says how fast. Estimating an integral ∫01g(x) dx\int_0^1 g(x)\,dx as the average of g(Ui)g(U_i) for uniform UiU_i is the law of large numbers applied to Xi=g(Ui)X_i = g(U_i).

python · try it yourself
import math
import random

rng = random.Random(9)
g = lambda x: math.exp(-x * x)
exact = math.sqrt(math.pi) / 2 * math.erf(1)
for n in [100, 10_000, 1_000_000]:
    est = sum(g(rng.random()) for _ in range(n)) / n
    print(f"n={n:8d}  estimate {est:.5f}  error {abs(est - exact):.5f}")
print("exact:", round(exact, 5))
n=     100  estimate 0.77823  error 0.03140
n=   10000  estimate 0.74916  error 0.00234
n= 1000000  estimate 0.74671  error 0.00011
exact: 0.74682

In software

Insurance pricing, casino economics, load averaging across many users and the reliability of averaged metrics all rest on the law of large numbers. Its failure modes matter too: averaging heavy-tailed data (file sizes, losses) converges very slowly, and correlated samples (all users in one region) do not average out.

Exercises

Exercise 1: Casino income

A casino takes 10,000 independent 1-unit roulette bets on red (win probability 18/3818/38). Using Chebyshev, bound the probability that the casino's average profit per bet is negative.

Answer

At most about 0.0360.036.

Solution

Per bet the casino gains +1+1 with probability 20/3820/38 and −1-1 otherwise: mean 2/38≈0.05262/38 \approx 0.0526, variance 1−0.05262≈0.9971 - 0.0526^2 \approx 0.997. Pr⁡[Xˉ≤0]≤Pr⁡[∣Xˉ−μ∣≥μ]≤0.99710000⋅0.05262≈0.036\Pr[\bar{X} \le 0] \le \Pr[\lvert \bar{X} - \mu \rvert \ge \mu] \le \frac{0.997}{10000 \cdot 0.0526^2} \approx 0.036. (The normal approximation puts the true probability near 7×10−87 \times 10^{-8}.)

Exercise 2: Swamping

You toss a coin and get 10 tails first. In 10,000 tosses total, what is the expected proportion of heads, counting the 10 tails?

Answer

4995/10000=0.49954995/10000 = 0.4995.

Solution

The remaining 9990 tosses give 4995 heads on average. The early deficit is diluted, not corrected.

Exercise 3: Slow convergence with heavy tails (code)

Compare running averages of exponential samples (mean 1) and Pareto samples with α=1.1\alpha = 1.1 (mean 11) at n=103,104,105,106n = 10^3, 10^4, 10^5, 10^6.

Answer

The exponential averages are close to 1 quickly; the Pareto averages stay well below 11 and move erratically.

Solution

With α=1.1\alpha = 1.1 the variance is infinite, so Chebyshev gives nothing and convergence is very slow.

python · try it yourself
import numpy as np

rng = np.random.default_rng(3)
n = 1_000_000
e = rng.exponential(1.0, n)
p = (1 - rng.random(n)) ** (-1 / 1.1)          # Pareto with alpha 1.1 on [1, inf)
for k in [10 ** 3, 10 ** 4, 10 ** 5, 10 ** 6]:
    print(k, round(e[:k].mean(), 4), round(p[:k].mean(), 3))
1000 1.014 4.386
10000 0.9919 7.116
100000 1.0024 6.555
1000000 1.0007 8.297

Test yourself

The weak law of large numbers follows directly from…

  1. Bayes' theorem
  2. Chebyshev's inequality and Var(Xˉn)=σ2/n\mathrm{Var}(\bar{X}_n) = \sigma^2/n
  3. the binomial theorem
  4. the central limit theorem only

After 10 tails in a row with a fair coin, the long-run proportion of heads still tends to 1/2 because…

  1. heads become more likely
  2. later tosses swamp the early ones
  3. the coin compensates
  4. it does not