Chapter 8: The law of large numbers and the central limit theorem

Previous: PS 07 The Multivariate Gaussian | PS 00 Course Map | Next: PS 09 Estimation and Maximum Likelihood

The big idea

Two theorems explain why data tells you anything at all. The law of large numbers says that the average of many independent samples settles down to the true mean. The central limit theorem says that the remaining random error of that average is approximately normal, with size , whatever the original distribution looked like. Together they are the bridge from probability (models to data) to statistics (data to models).

In this chapter you will learn to
  1. Treat a sample average as a random variable with its own mean and spread.
  2. State the law of large numbers, prove a version of it, and avoid the gambler’s fallacy.
  3. State the central limit theorem and use it to approximate probabilities about averages and sums.
  4. Compute standard errors for means and for proportions.
  5. Judge how large must be, and recognize when the theorems fail.
Before you start

You need the square-root law and Chebyshev’s inequality (PS 04 Expectation and Variance) and normal probabilities with z-scores (PS 05 Continuous Random Variables).


8.1 The sample average is a random variable

Setup

Let be i.i.d.: independent and identically distributed. Each has the same mean and variance . Think of repeated measurements, robot trials, or data points.

Definition: sample mean

Key mental shift. is itself random. Run the whole experiment again and you get a different set of samples, hence a different average. So has its own distribution, called its sampling distribution.

From chapter 4:

The average is centred on the truth, and its spread shrinks as grows. The two theorems describe what happens in the limit.


8.2 The law of large numbers

Law of large numbers (weak form)

For any tolerance ,

The sample average converges to the true mean.

Proof (it is short)

Apply Chebyshev’s inequality (PS 04 Expectation and Variance) to , whose variance is :

The right side goes to 0 as .

The bound also says how many samples are enough. To be within of the mean with probability at least 95%, when : need , so . (Chebyshev is pessimistic; the CLT below gives a much smaller number.)

What it means

  • Frequencies settle to probabilities. The fraction of heads in many fair flips approaches 0.5. This is what justifies the frequentist reading of probability.
  • Monte Carlo estimation. To estimate an expectation you cannot compute exactly, draw samples and average: Reinforcement learning estimates expected returns this way; training estimates the expected loss this way.

What it does not mean: the gambler’s fallacy

Deficits are diluted, not repaid

After 10 tails in a row, the next flip of a fair coin is still 50/50. The law of large numbers does not work by producing extra heads to “make up” for the tails.

It works by dilution. After 10 tails and then 1,000 more fair flips, the fraction of heads is about : close to 0.5, because the early streak is now a tiny part of the total. In fact the absolute difference between heads and tails typically grows, like . Only the fraction converges.


8.3 The central limit theorem

The statement

The law of large numbers says where goes. The central limit theorem (CLT) describes the shape of its fluctuations around that limit.

Central limit theorem

If are i.i.d. with mean and finite variance , then for large

or equivalently

Why it is astonishing

The shape of the original distribution does not matter. The can be coin flips (two values), dice (flat), exponential waiting times (very skewed): their averages all become bell-shaped. Only the mean and variance survive.

Why it happens (intuition)

Consider the sum of dice:

  • One die: flat, every value from 1 to 6 equally likely.
  • Two dice: a triangle peaking at 7 (chapter 1). Middle sums can be made in more ways.
  • Five dice: already looks like a bell.

Extreme totals need every die to be extreme in the same direction, which is rare. Middle totals can be reached in a huge number of ways. As more independent pieces are added, this effect overwhelms the shape of any single piece.

Standard error

Definition: standard error

The standard error of the mean is

It is the standard deviation of the estimate , as opposed to , the standard deviation of the data.

Mixing these two up is a very common error. The data stays just as spread out no matter how much you collect; the estimate of its mean becomes more precise.


8.4 Worked examples

Worked example 8.1: averaging sensor readings

A sensor reading has mean 20 and standard deviation 4. You average 64 independent readings. What is ?

Step 1: standard error. .

Step 2: CLT. .

Step 3: standardize. .

Step 4: probability. .

A single reading exceeds 21 quite often (about 40% of the time, if readings are roughly normal: ). The average of 64 almost never does.

Worked example 8.2: sum of dice

Roll 100 dice. ?

Each die: , . Total: mean , variance , sd .

(A continuity correction, using 370.5 for a discrete total, gives and , slightly more accurate.)

Worked example 8.3: exponential waiting times

Task times are exponential with mean 30 s (so s too: very skewed). The average of 36 tasks:

. Even though individual times are strongly skewed, their average is close to normal.


8.5 Proportions

The setup

Each trial succeeds with probability . The observed success rate in trials is

an average of Bernoulli variables, each with variance .

Sampling distribution of a proportion

Worked example 8.4: how precise is a success rate?

, : . About 95% of the time, lands within of the truth.

Consequence. A policy measured at 55% over 100 trials is indistinguishable from one at 50%. The difference is within ordinary noise.

How many trials do you need?

For a standard error of , solve :

Desired SE0.100.050.020.01
(worst case )251006252500

This is why opinion polls use about 1,000 to 2,500 people, and why a robot evaluation with 10 or 20 trials can only detect large differences between policies.


8.6 How large is “large ”?

There is no single answer. Rules of thumb:

  • If the underlying distribution is roughly symmetric, can already be fine.
  • A common general rule is .
  • For proportions, require at least about 10 expected successes and 10 expected failures: and .
  • For strongly skewed or heavy-tailed data, much larger may be needed.

When in doubt, simulate: draw many samples of size from a plausible distribution and look at the histogram of their averages.


8.7 When the theorems fail

Both theorems assume independent samples, from the same distribution, with finite variance.

Dependence

Samples from the same robot episode, consecutive video frames, or many measurements of one object are correlated. Correlated errors do not cancel the way independent ones do (PS 06 Joint Distributions and Covariance, exercise C4). The true uncertainty is larger than , sometimes much larger.

Count independent units, not rows

10 robot episodes of 1,000 frames each is closer to 10 independent samples than to 10,000 for questions about task success. Treating it as 10,000 makes error bars about 30 times too small.

Changing distribution

If the process drifts (a motor warms up, lighting changes, a policy is being trained), the samples are not identically distributed. The average tracks a moving target and may not mean anything simple.

Infinite variance

Some distributions have such heavy tails that their variance is infinite (the Cauchy distribution is the standard example). Then averaging does not reduce noise: one enormous value can dominate any average, however large is. Real data with occasional extreme outliers can behave similarly in practice.


Summary

IdeaFact
sample meanrandom, with mean and sd
LLN
CLT for any shape
standard error (spread of the estimate, not the data)
proportion
required for SE

Three facts to remember:

  1. Averages converge to the mean by diluting early luck, not by correcting it.
  2. Averages are approximately normal with standard error .
  3. Count independent units; correlated samples overstate how much you know.

Exercises

Part A: warm-up

A1. Data has . What is the standard error of the mean for ? For ?

A2. A fair coin is flipped 400 times. Give an interval that contains the number of heads about 95% of the time.

A3. A policy’s true success rate is 0.8. In 25 trials, what is the standard error of the observed rate?

A4. How many trials are needed to estimate a success rate near 0.9 with a standard error of 0.03?

Part B: core

B1. A robot’s cycle time has mean 12 s and standard deviation 3 s. Over 100 cycles, what is the probability the total time exceeds 1,250 s?

B2. Two policies are evaluated on 50 independent trials each. A truly succeeds 70% of the time, B 60%. Approximately what is the probability that B’s observed rate is higher than A’s? (Hint: the difference is approximately normal; find its mean and standard deviation.)

B3. An election poll of 1,000 people finds 52% support. Is this convincing evidence of majority support? Use the standard error.

B4. Explain why the following claim is wrong: “My dataset has 50,000 frames from 20 demonstrations, so the standard error of my success estimate is tiny.”

B5. Use Chebyshev to find how many samples guarantee when . Then use the CLT to estimate the number needed. Compare.

Part C: explain and prove

C1. Prove that for independent samples. Where exactly is independence used?

C2. Explain, using the formula for the variance of a sum with covariance, why positively correlated samples make larger than .

C3. Explain the difference between “the standard deviation of the data” and “the standard error of the mean” to a friend, with an example.

Part D: practise with code

D1. For dice, plot histograms of the average of dice (10,000 repetitions each). Watch the bell shape appear.

D2. Repeat D1 with exponential samples (rng.exponential(1, ...)), which are strongly skewed. How large must be before the histogram looks symmetric?

D3. Simulate 10 tails followed by 10,000 fair flips. Plot the running fraction of heads and the running difference (heads minus tails). One converges; one does not.

D4. Simulate averages of Cauchy samples (rng.standard_cauchy) for . Do they settle down?


Where this is used

Next: PS 09 Estimation and Maximum Likelihood: turning data into fitted models.