The sample mean is a random variable
Roll a die 10 times and average the results. Roll 10 more and the average changes. Before the rolls are made, their average is a random variable, with a distribution of its own.
Write for draws that are independent and identically distributed, or i.i.d.: independent (lesson 5.1.3), and each with the distribution of one draw . That draw has mean and variance .
The sample mean is
Rule: Mean and variance of the sample mean
By linearity the sum has mean ; dividing by gives . The variances of independent draws add up to , and dividing by divides the variance by (lesson 5.3.2). The standard deviation is called the standard error of the mean: the typical size of the miss .
For a die, and :
| rolls | 1 | 10 | 100 | 1,000 | 10,000 |
|---|---|---|---|---|---|
| 2.916667 | 0.291667 | 0.029167 | 0.002917 | 0.000292 | |
| 1.7078 | 0.5401 | 0.1708 | 0.054 | 0.0171 |
Four times the rolls halve the standard error, and a hundred times divide it by 10. The variance falls like ; the standard error only like .
Lesson 5.6.3 met this for normals, where the mean of draws is exactly . The mean and variance hold for any distribution; the shape is lesson 5.7.3's subject. Case study 5.3.5 used the same rule: with , the mean of 1,000 daily returns has standard error .
Try it
The loop prints the table. Then, for each , 2,000 seeded repetitions of rolls: each row of the array is one repetition, and .mean(axis=1) averages each row.
The 2,000 sample means centre on 3.5, and their standard deviation is close to : 0.5353, 0.1741 and 0.0537 in this run. The last line is case study 5.3.5's standard error, in percent.
The law of large numbers
With a spread that shrinks to 0, the sample mean must close in on . Chebyshev's inequality (lesson 5.7.1), applied to with its variance , makes that precise.
Rule: Law of large numbers
For i.i.d. draws with mean and finite variance , and any distance . However small a miss you name, the chance of missing by that much shrinks to 0. The law still holds when the variance is infinite, as long as the mean exists; then the bound is not available.
The bound also says how many draws are enough. For a die and a miss of , it is : 0.2917 with 1,000 rolls and 0.0292 with 10,000.
The true chance is smaller. In 4,000 seeded repetitions of 1,000 rolls, the share that missed 3.5 by 0.1 or more was 0.0712, against the bound's 0.2917. Chebyshev's inequality must hold for every distribution, so it is cautious.
To push the bound down to , solve : , here 5,834 rolls. Lesson 5.7.3 shows that about 1,121 rolls do the same job.
Try it
The first loop prints the bound for . Then the share of 4,000 seeded repetitions of 1,000 rolls that missed by at least 0.1.
math.ceil rounds the guaranteed number of rolls up to a whole roll. The next line is and for 5,000 rolls, for the explorer below.
The last line is at 10,000 rolls, and how many times wider Chebyshev's 95% guarantee is, for the figure.
One long run
The rule speaks about many repetitions of draws. A stronger version, the strong law of large numbers, speaks about one endless run: its running mean settles on with probability 1. That is what a single simulation shows.
Choose the die and 5,000 draws. The readout compares the miss with .
Press "Draw again" several times: each run wanders differently at first, and most end within of 3.5. Then try the exponential, whose rare long draws make visible jumps.
Explore
Each point is the average of the first k draws. Pick a starting distribution and watch the running mean settle on the true mean as k grows; draw again for a different run.
- True mean and standard deviation
- μ = 3.5, σ = 1.7078
- Mean of 1000 draws
- 3.565, off by 0.065; a typical miss is σ/√n = 0.054
Twenty runs of 10,000 rolls settle on 3.5 inside a band that narrows like . Chebyshev's guarantee, dashed, is about 2.24 times wider.
Shares settle on probabilities
A share is a mean in disguise. For an event , let the indicator be 1 when happens and 0 when not. It has mean and variance (lesson 5.3.2).
The share of independent trials in which happens, written , is the sample mean of indicators. The rules above apply with and .
Rule: A share
The share of successes in independent trials, each a success with probability , settles on . Its standard error shrinks like , and is largest at .
This is why the share of sevens in lesson 5.1.1 settled on , and how fast. Its standard error is 0.0373 after 100 rolls, 0.00373 after 10,000 and 0.000373 after a million.
That run's shares, 0.19, 0.1652 and 0.1665, missed by 0.0233, and . Each miss is less than one standard error: 0.63, 0.39 and 0.45 of one.
Case study 4.7.5 attached a standard error to a simulated probability. It is this rule with the unknown replaced by its estimate : with draws and it is 0.00169. How often the miss stays within two standard errors is lesson 5.7.3's question.
Try it
The first loop is lesson 5.1.1's sevens: the standard error at each , that run's miss, and the miss in standard errors.
The second loop recomputes case study 4.7.5's standard errors from its estimates.
Simulation as a way to compute rests on this law. Case study 4.7.5 estimated a probability as a share, and case study 5.7.5 estimates an option price as an average.
What the law does not say
Nothing is certain at a fixed . Ten rolls can all show 6, with probability , and then . The law makes large misses unlikely, never impossible.
There is no law of averages. Toss a fair coin times. The number of heads minus has standard deviation : 5 after 100 tosses, 50 after 10,000, 500 after a million.
That gap grows. Only the share closes in on , because dividing by beats a gap that grows like .
Nothing pushes the coin back towards even. After ten tails in a row, the next toss is still heads with probability , by independence. Expecting otherwise is the gambler's fallacy.
It needs a mean. A Student t with degree of freedom has no mean (lesson 5.4.4). Its running mean never settles: rare, enormous draws keep jolting it.
Lesson 5.3.1's coin game with no finite expected value behaves the same.
It needs independence, or something close to it. If every "draw" is a copy of the first, for every , and nothing settles. Draws that are positively correlated settle more slowly than says.
Try it
First the chance of ten sixes. Then one seeded run of a million coin tosses: at each , heads minus , the share of heads, and . In this run the gap grows from 4 to 47 to 460 while the share closes in from 0.54 to 0.5005.
The last line is the running mean of a million seeded t draws with , after of them. It jumps about without settling.
Common mistakes
- The standard error is , not . It is the variance that is divided by . A hundred times the draws give ten times the accuracy.
- There is no law of averages. Past draws do not make up for each other; each new draw is independent of them.
- The sum does not settle; the mean does. Heads minus grows like while the share closes in.
- The law promises nothing for a particular . Chebyshev's inequality gives a bound, and only a bound.
- No mean, no law. The running mean of t draws with never settles.
- Copies are not independent draws. Averaging the same number times does not shrink its error.
The law of large numbers
0 of 11 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- For i.i.d. draws with mean and variance , the sample mean has mean , variance and standard error .
- Law of large numbers: , and with a finite variance it is at most (Chebyshev). One long run settles on too.
- A share is a mean of indicators. It settles on with standard error , estimated as in a simulation.
- The law gives no certainty at a fixed and no law of averages: the count's gap grows like . It needs a mean, and independence.