Skip to content

The law of large numbers

Averages settle down as you add draws, but no draw ever makes up for an earlier one. See when the law works, and the one case where it fails.

Introductory ~9 min8 steps

What runs in CodeSplash

You will be able to

  • State what the law of large numbers promises
  • Tell it apart from the gambler's fallacy
  • Say why simulations get more accurate as draws are added, and how fast

Read first

01

Averages settle down

Read

The law of large numbersLaw of large numbersThe average of many independent draws gets close to the expected value, if one exists. says that the average of independent draws gets closer and closer to the expected value as you add draws, if that expected value exists.

Xˉn=1n∑i=1nXi  ⟶  E[X]\bar X_n = \frac{1}{n}\sum_{i=1}^{n} X_i \;\longrightarrow\; E[X]

It's why casinos, insurers and simulations can plan on long-run averages, even though single outcomes are unpredictable.

02

After a run of heads

Predict

Predict first

A fair coin has landed heads 8 times in a row. What is the chance of heads on the next flip?

Tails is more likely nowHeads is more likely nowStill a half
Reveal

Still a half. The coin has no memory, and nothing evens out. The average settles because later flips dilute the early run, and no flip corrects it. That gap between the law and the belief is the gambler's fallacy.

03

Watch the averages

Explore

Each line is a running average. Guess how far off it will be, then raise Draws n and Running averages. Then switch Population to Cauchy, or use the break-it setting. What happens to the lines?

AExplorable · The law of large numbers

Does the average of more and more draws settle on the true mean?

After all n draws, how far from the true mean will a running average typically be?

0.500
How sure?

Population

1000
6
true mean

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

04

When there's nothing to settle on

Read

The law needs a finite expected value. A Cauchy distribution has so much weight in its tails that a single huge draw can move the average at any point, however many draws came before.

Real data with very heavy tails, such as incomes or claims, can behave a bit like this: the running average lurches when an extreme value arrives. The median is often steadier.

05

How simulations get accurate

Explore

A simulation's accuracy follows the same law. Its error is about SD/n\text{SD} / \sqrt{n}.

One stocking simulation has a standard deviation of 1,653 over 5,000 scenarios, so its average is good to about 1653/5000≈231653 / \sqrt{5000} \approx 23. Try this: run the code and change the number of draws.

Python
import numpy as np

rng = np.random.default_rng(1)
for n in [100, 10_000, 1_000_000]:
    draws = rng.exponential(scale=1.0, size=n)
    print(n, round(draws.mean(), 4))
R
set.seed(1)
for (n in c(100, 10000, 1000000)) {
  draws <- rexp(n, rate = 1)
  cat(n, round(mean(draws), 4), "\n")
}
06

Check your reading

Checkpoint

Check yourself

What does the law of large numbers promise?

Show the answer

Answer: b

It concerns averages, and only in the long run. It says nothing about the next draw, and it doesn't protect a biased sampling method.

Check yourself

After 1,000 flips of a fair coin you have 520 heads. What do you expect after 1,000 more flips?

Show the answer

Answer: b

You expect 500 more heads, for 1,020 in all. The share falls from 52% to 51%, even though the raw excess stays at 20.

Check yourself

You want a simulation's error to be 10 times smaller. How many times as many draws do you need?

Show the answer

Answer: 100

The error falls with n\sqrt{n}, so ten times smaller takes 102=10010^2 = 100 times the draws.

07

Try it in the app

In the app

Any Monte Carlo result in CodeSplash depends on this law: a permutation p-value, a bootstrap interval or a scenario simulation. Raise the replications when the result needs to be more stable. Try it with Monte Carlo permutations in this test.

08

Recap

Recap
  • Averages of independent draws settle on the expected value, if one exists.
  • They settle by dilution. Nothing evens out, so the next flip is still a coin flip.
  • Simulation error falls with n\sqrt{n}: ten times better takes a hundred times the draws.

Concepts in this lesson