Law of Large Numbers

If you flip a fair coin many times, the fraction of heads gets closer and closer to 1/2. If you roll a fair die many times, the average roll gets closer and closer to 3.5. This is not just an empirical observation. It is a mathematical theorem, and it is one of the pillars of probability theory.

The example program for this chapter is in the file 06_law_of_large_numbers.lisp.

Historical Roots

Jakob Bernoulli, in his posthumous Ars Conjectandi (1713), proved the first version of what we now call the Law of Large Numbers for Bernoulli trials. He called his result the “Golden Theorem” and considered it his most important contribution. In modern language, Bernoulli’s theorem says that the sample proportion of successes converges to the true probability Code Test as the number of trials grows. Bernoulli was proud enough of his result to spend twenty years polishing it before publication.

The name we use today came later. Siméon Denis Poisson, in 1837, restated and broadened Bernoulli’s result and attached to it the phrase it still carries: la loi des grands nombres, the law of large numbers.

Later refinements by Chebyshev in the nineteenth century, and eventually by Khinchin and Kolmogorov in the twentieth, extended the theorem to arbitrary i.i.d. random variables with finite mean. Chebyshev’s contribution was a simple but powerful inequality (Chapter 3) that gives a proof of the Weak Law of Large Numbers in a few lines. Kolmogorov’s Strong Law is more delicate but rests on the same intuition: averages of many i.i.d. quantities converge to the underlying mean.

The Sample Mean

Let Code Test be independent and identically distributed (i.i.d.) random variables with finite mean Code Test. The sample mean after Code Test observations is:

math

By linearity of expectation, Code Test for every Code Test. The sample mean is always centered on the true mean. But what about its variability?

If the individual variance is Code Test, then by additivity of variance for independent variables:

math

The variance of the sample mean shrinks as Code Test grows. Its standard deviation, which is the natural scale for measuring “typical” deviations, shrinks as Code Test. This Code Test rate is fundamental. It says the sample mean concentrates around the true mean, but only slowly: reducing the uncertainty by a factor of Code Test requires Code Test times more data.

The Weak Law of Large Numbers

The Weak Law of Large Numbers states that for any positive number Code Test, no matter how small:

math

In plain language: as the sample size grows, the probability that the sample mean deviates from the true mean by more than any fixed amount shrinks to zero. The sample mean converges in probability to the true mean.

A Proof Sketch Using Chebyshev

The Weak Law has a beautifully short proof using Chebyshev’s inequality (Chapter 3). Applied to Code Test:

math

As Code Test grows, the right-hand side goes to zero, and so the left-hand side must too. This gives convergence in probability directly. The proof relies only on Chebyshev’s inequality and additivity of variance, both of which are elementary. Bernoulli’s original proof used a much more intricate combinatorial argument; Chebyshev’s cleaner path is the one usually taught today.

The Strong Law of Large Numbers

The Strong Law of Large Numbers goes further. It states that:

math

This means that for almost every possible sequence of outcomes, the sample mean eventually settles down to Code Test and stays there. The strong law is a stronger statement than the weak law because almost-sure convergence implies convergence in probability but not vice versa.

The difference between the two laws is subtle. The Weak Law says that at each large Code Test, the sample mean is probably close to Code Test. The Strong Law says that if we watch the whole sequence Code Test, the sequence itself converges to Code Test with probability Code Test. For most practical purposes the two laws give the same guarantee, but the strong law is what the theoretical statistician wants.

The Borel-Cantelli Lemmas

Almost-sure statements like the Strong Law are usually proved with a pair of results called the Borel-Cantelli lemmas, which connect the probabilities of a sequence of events to whether infinitely many of them occur. Write Code Test for the event that infinitely many of the Code Test happen (“infinitely often”).

The first lemma says that if the probabilities are summable, the events almost surely stop happening:

math

The second lemma is a partial converse: if the Code Test are independent and their probabilities are not summable, then almost surely infinitely many occur:

math

To see how this powers a strong law, let Code Test be the event that the sample mean is far from Code Test at step Code Test. If we can show Code Test, the first lemma says these deviations stop happening for good, which is exactly almost-sure convergence. The Chebyshev bound Code Test gives terms of order Code Test, whose sum diverges, so a naive application falls just short. Kolmogorov’s proof closes the gap by working along a cleverly chosen subsequence and controlling the values in between with a maximal inequality. The Borel-Cantelli lemmas are the reason almost-sure convergence can be established at all, and they recur throughout the study of random sequences.

Modes of Convergence

The distinction between weak and strong laws is a special case of a broader theme in probability: different notions of “convergence of random variables.” A brief tour:

  • Convergence in probability: for every Code Test, Code Test. This is what the Weak Law provides.
  • Almost sure convergence: the sequence Code Test converges to Code Test pointwise, on all sample paths outside a set of probability zero. This is what the Strong Law provides.
  • Convergence in distribution: the CDFs Code Test converge to Code Test at every continuity point of Code Test. This is the weakest notion; it is what the Central Limit Theorem in the next chapter provides.
  • Convergence in mean square: Code Test.

These modes are related by implications: almost sure implies in probability; in probability implies in distribution; mean square implies in probability. Whenever a probability textbook talks about convergence of random variables, it is worth pausing to check which mode is being used.

When the Law of Large Numbers Fails

The Law of Large Numbers requires finite mean. When the mean does not exist, the sample mean does not converge to any deterministic value. The classic pathological example is the Cauchy distribution, which has PDF:

math

The Cauchy distribution has infinitely heavy tails and no finite mean. Sample means of Cauchy-distributed variables do not settle down; instead, they themselves are Cauchy-distributed. Simulating a million Cauchy draws and averaging them gives an answer that is just as noisy as a single draw. This is a striking counterexample and a reminder that “average enough data” is not a universal solution.

For distributions with finite mean but infinite variance, the Weak Law still holds (in a slightly more delicate form) but the variance-based Chebyshev proof does not apply, and the rate of convergence can be much slower than Code Test. Heavy-tailed distributions appear in finance, network traffic, and other real settings where the LLN’s guarantees are still true but weaker than the standard textbook picture suggests.

Why This Matters

The Law of Large Numbers is the theoretical justification for using sample averages as estimates of true means. When a pollster surveys 1,000 people and reports that 52% support a candidate, they are relying on the LLN: with a large enough sample, the sample proportion will be close to the true population proportion. When a scientist repeats an experiment many times and averages the results, the LLN guarantees that the average converges to the expected value.

The LLN also explains why casinos always make money in the long run. Each individual bet is random, but over thousands of bets, the average outcome converges to the house edge. The randomness averages out.

The LLN is also the theoretical foundation of Monte Carlo methods (Chapter 8), where we estimate expectations by simulating many samples and averaging them. Every Monte Carlo estimator is a direct application of the LLN.

The Simulation

The program demonstrates the LLN by simulating a fair die and a Bernoulli process, tracking the sample mean as n grows from 10 to 1,000,000:

1 (defun roll-die ()
2   "Simulate one roll of a fair six-sided die: uniform on {1,...,6}."
3   (+ 1 (random 6 *rng-state*)))
4 
5 (defun sample-mean-of-rolls (n)
6   "Compute M_n = average of n die rolls. By the LLN this approaches 3.5."
7   (/ (loop for i below n sum (roll-die)) n))

For the fair die, the true mean is Code Test. For the Bernoulli process with Code Test, the true mean is Code Test.

Running the Example

 1 === Law of Large Numbers: Fair Die (mu = 3.5) ===
 2        n     M_n     |M_n - mu|
 3   10        3.8000    0.3000
 4   100       3.3300    0.1700
 5   1000      3.4510    0.0490
 6   10000     3.5415    0.0415
 7   100000    3.5015    0.0015
 8   1000000   3.4960    0.0040
 9 
10 === Law of Large Numbers: Bernoulli(p=0.3) ===
11        n     M_n     |M_n - p|
12   10        0.2000    0.1000
13   100       0.3500    0.0500
14   1000      0.3160    0.0160
15   10000     0.3003    0.0003
16   100000    0.2977    0.0023
17   1000000   0.3000    0.0000

Watch the column Code Test shrink as Code Test grows. With only Code Test rolls, the sample mean can be off by Code Test or more. By Code Test rolls, the deviation is typically under Code Test. By Code Test, it is essentially zero. This is the Law of Large Numbers in action. The program reseeds its random state on each run, so your exact numbers will differ, but the shrinking trend is always the same.

The convergence is not perfectly monotonic. You can see that the die simulation at Code Test has a slightly larger deviation than at Code Test. This is expected: the LLN guarantees convergence in the long run, but individual samples can fluctuate. The trend is what matters.

A Practical Observation

Notice that the deviation shrinks roughly as Code Test, not as Code Test. Going from Code Test to Code Test samples reduces the error by about a factor of Code Test (roughly Code Test), not a factor of Code Test. This slow convergence rate is a fundamental limitation of averaging. To halve the error, you need about Code Test times as much data. We will see this Code Test rate appear again in the Monte Carlo chapter.

The Code Test rate is not a defect of a particular simulation; it is a consequence of the fact that Code Test. Standard deviations scale as the square root of variance, so typical deviations of Code Test from Code Test scale as Code Test. This is a universal law for i.i.d. averages with finite variance.

Problem Set

Problem 6.1. For the fair-die simulation, plot (on paper if necessary) the sample mean Code Test as a function of Code Test. Add a horizontal line at Code Test and dashed lines at Code Test using Code Test. Describe how the sample mean fluctuates relative to those confidence bands.

Problem 6.2 (Chebyshev bound). For a fair die (Code Test, Code Test), use Chebyshev’s inequality to bound Code Test. Compare against the empirical frequency of this event by running the simulation Code Test times.

Problem 6.3 (Different distributions). Modify the example program to simulate the sample mean of an exponential distribution with rate Code Test. True mean is Code Test. Watch the sample mean converge to Code Test as Code Test grows. Because the exponential is more heavily right-skewed than the fair die, does convergence appear faster or slower?

Problem 6.4 (The Cauchy failure). Add a function that samples from a Cauchy distribution using inverse-CDF: draw Code Test from Code Test and return Code Test. Compute the sample mean for Code Test Cauchy samples. Does the sample mean converge, or does it keep jumping around? Explain what you observe in terms of the LLN’s assumption of finite mean.

Problem 6.5 (Empirical variance of M_n). Run Code Test independent simulations of a sample mean of Code Test die rolls. Record the Code Test sample means and compute their variance. Compare against the theoretical prediction Code Test.

Problem 6.6 (Rate of convergence). For the Code Test coin, empirically estimate the rate at which Code Test shrinks. Fit a curve of the form Code Test to the deviations at Code Test, and estimate Code Test. Does your estimate come out close to Code Test as the theory predicts?

Problem 6.7 (Coding exercise). Extend the example program to a function lln-demo that takes a sampling procedure (a thunk returning one sample) and a true mean, and prints a table of the same form as the example’s die output. Test your function on the die, the Bernoulli, and the exponential.

Problem 6.8 (Almost sure vs. in probability). Describe informally what it would look like if the sample mean of a die converged in probability but not almost surely. Would the running sample mean have to keep spiking away from Code Test forever, or only rarely? Even without a rigorous treatment, this thought experiment sharpens the distinction between the two modes of convergence.