The sampling distribution of the mean
Lesson 5.8.1 found that the sample mean of independent draws has mean and variance . Its distribution over all possible samples is its sampling distribution. Its standard deviation has its own name.
Rule: Standard error of the mean
The standard error of an estimator is its standard deviation: the typical size of its error. It is in the units of the data. When is unknown, the sample standard deviation of lesson 5.8.1 stands in for it.
The shape is known too. For normal draws, exactly (lesson 5.6.3). For any other distribution with a finite variance it is close to that for large , by the central limit theorem.
An example. Exponential draws with mean 1 have (lesson 5.4.2), so the mean of 30 has standard error . The total of 30 exponentials has a gamma distribution (lesson 5.6.3 met the total of two), so the exact answers are known:
| exact | normal approximation | simulated | |
|---|---|---|---|
| 0.5243 | 0.5 | 0.5253 | |
| 0.9519 | 0.95 | 0.9509 |
The skew of the exponential leaves a trace: slightly more than half the means fall below . But the band of standard errors holds almost exactly 95% of them.
Two case studies used this rule already. In case study 5.3.5, 1,000 daily returns with volatility 1% have a mean with standard error . Case study 4.6.5 quoted for an annual mean from years. Each year is one draw with standard deviation , so ; for B that is .
Try it
gamma(30, scale=1/30) is the exact distribution of the mean of 30 exponentials with mean 1. The first line prints the standard error and the two exact probabilities.
Then 100,000 seeded samples of 30: the mean and standard deviation of their means, and the two shares. The last line is the two case studies' standard errors.
A confidence interval when is known
Standardise the mean: is standard normal, exactly or approximately. So (lesson 5.4.3). Rearranged, the same event says that lies within of .
Rule: Confidence interval for μ, σ known
For a confidence level , is norm.ppf(1 - α/2), leaving in each tail. The interval runs from to ; half its width is the margin of error.
Roll a die 30 times; its is known. One seeded sample has . The margin at 95% is , so the interval 3.1222 to 4.3445 contains the true mean 3.5.
- More confidence costs width. At 90% the margin is 0.5129; at 99% it is 0.8032.
- More data buys width slowly. The margin shrinks like : four times the rolls, 120, halve it to 0.3056.
Try it
The loop prints, for each level, , the margin and the interval for the seeded sample of 30 rolls.
The last line prints , and the 95% margin for 120 rolls.
What "95%" means
Before the rolls, the interval is random: its centre changes from sample to sample. The 95% is the chance that this procedure produces an interval that covers . It is called the interval's coverage.
After the rolls, the interval from 3.1222 to 4.3445 is fixed, and so is . Either it contains or it does not; nothing random is left. "95% confidence" describes the method, not this one interval.
In one seeded run of 10,000 samples of 30 rolls, 95.58% of the intervals cover 3.5. The exact share, from the distribution of the total of 30 dice, is 0.9525. It is a little above 95% because that total moves in whole steps.
The explorer starts with the die. Set : the share of means within of is the share of intervals that cover . Then try the coin with small : its mean takes only a few values, and the share jumps around 95%.
Explore
Each bar counts how many of 2,000 samples had their mean in that range. Raise the sample size n: the histogram narrows like 1/√n and takes the shape of the normal curve, even from a skewed start.
- True mean and standard deviation
- μ = 3.5, σ = 1.7078
- The 2000 sample means
- average 3.5223, standard deviation 0.7615 against σ/√n = 0.7638
- Within 1.96 σ/√n of μ
- 94% of the means (the normal curve says 95%)
Try it
The first lines draw 10,000 seeded samples of 30 rolls and print the share of intervals that cover 3.5.
The loop builds the exact distribution of the total of 30 dice by convolution, one die at a time (lesson 5.6.3). The last line adds up the totals whose interval covers 3.5.
When is unknown: the t interval
In practice is unknown, and the sample standard deviation takes its place. But varies from sample to sample, and now and then it is much too small. Then the standardised mean is too large, so it has fatter tails than a normal.
Rule: The standardised mean with s
For normal draws, has the Student t distribution with degrees of freedom (lesson 5.4.4), the same that divides by. For other distributions it is approximately for large .
This is lesson 5.4.4's ratio , with . Divide top and bottom by :
For normal draws is and independent of (stated here); the next section uses .
Rule: t interval for μ
The 95% interval when is estimated. For 90% or 99%, use the 0.95 or 0.995 quantile.
| 2 | 5 | 10 | 30 | 100 | normal | |
|---|---|---|---|---|---|---|
| , 0.975-quantile | 12.706 | 2.776 | 2.262 | 2.045 | 1.984 | 1.960 |
For the multiplier is 2.776 instead of 1.96, as lesson 5.4.4 found: small samples need wider intervals. From about 30 draws on, the difference is small.
Five measurements. A quantity is measured five times: 10.2, 9.6, 10.9, 10.4 and 9.9. Then , , , and the standard error is . The margin is , so the 95% interval runs from 9.5854 to 10.8146.
With 1.96 in place of 2.776, the margin would be 0.4339: too narrow. The coverage of such an interval is for :
| 5 | 10 | 30 | |
|---|---|---|---|
| coverage of | 0.8784 | 0.9184 | 0.9403 |
| coverage of the t interval | 0.95 | 0.95 | 0.95 |
The same 100 samples of five, with two multipliers. Highlighted intervals miss the true value 10: 5 with the t quantile, 10 with 1.96. Each interval's length depends on its own .
Try it
The first lines compute the five-measurement interval by hand. t.interval is SciPy's shortcut for the same interval. Then the t quantiles of the table.
Data that are not normal
The t interval assumes normal draws. For other data it relies on the central limit theorem, so it works for large samples and can fall short for small, skewed ones. For exponential draws its coverage is 90.09%, 92.72% and 94.18% at = 10, 30 and 100, in seeded runs.
Try it
The first loop is the exact coverage of from the t distribution. Next, 100,000 seeded normal samples of five: about 88% of the 1.96 intervals cover 10, against 95% for the t intervals.
The last loop repeats the t interval on 50,000 seeded exponential samples of each size.
An interval for a variance
The above gives an interval for itself. For normal draws, lies between the 0.025- and 0.975-quantiles of with probability 0.95. Solving both ends for gives the interval.
Rule: Interval for σ², normal data
is chi2.ppf(p, n - 1). Dividing by the larger quantile gives the lower end. Take square roots of both ends for an interval for .
For the five measurements, and the quantiles of are 0.4844 and 11.1433. So lies between 0.0879 and 2.023, and between 0.2966 and 1.4223.
The estimate is far from the middle: the interval stretches to the right, because is skewed (lesson 5.4.4). Five values say little about a spread.
This interval needs normal data much more than the t interval does. A fat tail (lesson 5.3.3) makes swing more than allows.
Take samples of 30, in one seeded run. The coverage is 94.99% for normal draws, but 82.54% for a Student t with 5 degrees of freedom.
Try it
The first lines compute the interval for the five measurements, for and for .
The loop checks coverage with 50,000 seeded samples of 30. First come normal draws with , then t draws with 5 degrees of freedom, whose variance is (lesson 5.4.4).
The bootstrap
The intervals so far needed a formula for the sampling distribution. When there is none, the bootstrap simulates it from the data. It treats the sample as if it were the whole population, and draws new samples from it.
Rule: Bootstrap percentile interval
Draw values from the sample with replacement, so some repeat and some are left out, and compute the estimate . Repeat times, say 10,000. The 0.025- and 0.975-quantiles of the estimates form a 95% interval.
Take 40 seeded exponential draws with mean 1. Their mean is 1.0984 and . The median, the middle value, is 0.7425; the true median of this distribution is .
| statistic | estimate | bootstrap 95% interval | formula interval |
|---|---|---|---|
| mean | 1.0984 | 0.7287 to 1.5262 | t: 0.6759 to 1.5209 |
| median | 0.7425 | 0.2667 to 1.0386 | none in this module |
For the mean, the standard deviation of the 10,000 bootstrap means is 0.2055, close to . The bootstrap interval is not centred on 1.0984: it leans right, as the skewed data do. For the median, the bootstrap gives an interval where this module has no formula.
The bootstrap has limits.
- It needs independent draws. For a time series, whose values depend on their neighbours, resample blocks of neighbouring values instead.
- It cannot see what the sample lacks. A small sample without its distribution's rare extremes gives bootstrap samples without them too.
- It is a simulation. Use many resamples and a fixed seed, so the interval does not move from run to run.
Case study 5.8.5 bootstraps a Sharpe ratio.
Try it
idx holds 10,000 rows of 40 positions drawn with replacement, and data[idx] the resampled values. Each row's mean and median is one bootstrap estimate.
The lines print the sample's statistics, the bootstrap interval and standard deviation of the mean, the t interval, and the bootstrap interval of the median.
Lesson 5.8.3 turns the same standardised mean into a test of a claimed value of .
Common mistakes
- "There is a 95% chance that lies between 9.5854 and 10.8146." Not so: once computed, the interval contains or does not. The 95% belongs to the method.
- Using 1.96 with in a small sample. With five values it covers only 87.84% of the time; use .
- Confusing standard deviation and standard error. measures the spread of single draws; measures the spread of their mean.
- Expecting twice the data to halve the interval. It takes four times the data.
- Reading the variance interval as symmetric. It stretches to the right, and it is reliable only for normal data.
- Expecting the bootstrap to add information. It reuses the sample, so it cannot fix a small or unrepresentative one.
Sampling distributions and confidence intervals
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
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
- The sample mean has standard error , estimated by . It is normal for normal draws and close to normal for large otherwise.
- With known, with , 1.96, 2.576 for 90%, 95%, 99%. "95%" is the coverage of the method over samples, not a probability about one computed interval.
- With estimated, for normal draws, so use : 2.776 for , near 1.96 from .
- For normal draws , which gives a skewed interval for ; fat tails break it.
- The bootstrap resamples the data with replacement and reads an interval from the quantiles of the recomputed estimates; it needs independent draws.