The Law of Large Numbers
Why does the proportion of heads approach ? 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 be independent with the same distribution, mean and finite variance , and let . For every :
Proof. and (Variance). By Chebyshev's inequality,
That is the whole proof: the variance of the average shrinks like .
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 drifts from by about , 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 . The weak law only says that for each large , a big deviation is unlikely.
The gambler's fallacy, simulated
After 10 tails in a row, the next toss is still heads with probability , yet the long-run proportion still goes to . Both are true at once:
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 as the average of for uniform is the law of large numbers applied to .
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 ). Using Chebyshev, bound the probability that the casino's average profit per bet is negative.
Answer
At most about .
Solution
Per bet the casino gains with probability and otherwise: mean , variance . . (The normal approximation puts the true probability near .)
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
.
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 (mean 11) at .
Answer
The exponential averages are close to 1 quickly; the Pareto averages stay well below 11 and move erratically.
Solution
With the variance is infinite, so Chebyshev gives nothing and convergence is very slow.
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…
- Bayes' theorem
- Chebyshev's inequality and
- the binomial theorem
- 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…
- heads become more likely
- later tosses swamp the early ones
- the coin compensates
- it does not