An estimator is a random variable
A distribution has fixed numbers that describe it, such as its mean , its variance or a coin's chance of heads . Such a number is a parameter, written (theta) in general. In practice is unknown, and data are used to guess it.
The data are a sample : independent draws, each with the same distribution. This is often shortened to i.i.d., independent and identically distributed.
Rule: Estimator and estimate
An estimator is a rule applied to the sample; the hat marks it. Before the draws it is a random variable, with a mean, a variance and a distribution of its own. Its value for one observed sample is an estimate, a single number.
Take a fair die, whose mean we pretend not to know, and the estimator from two rolls. The 36 equally likely pairs give 11 possible values:
| 1 | 1.5 | 2 | 2.5 | 3 | 3.5 | 4 | 4.5 | 5 | 5.5 | 6 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| pairs | 1 | 2 | 3 | 4 | 5 | 6 | 5 | 4 | 3 | 2 | 1 |
This is the two-dice total of lesson 5.6.3, halved. Its mean is , the true , and its variance is .
Five seeded samples of two rolls give the estimates 2.5, 1, 4.5, 3.5 and 3: one rule, five different numbers. The distribution of an estimator over all possible samples is its sampling distribution, which lesson 5.8.2 studies.
Try it
The loop lists the 36 pairs and collects the probability of each value of as a fraction. The first line printed counts the pairs behind each value.
Then the exact mean and variance, and five samples of two rolls with a fixed seed.
Bias, variance and mean squared error
A good estimator lands close to . Three numbers measure how close: where it is centred, how widely it scatters, and the two combined.
Rule: Bias, variance and MSE
An estimator is unbiased when its bias is 0 for every value of . The mean squared error (MSE) is in 's units squared; its square root is in 's units. The split is lesson 5.3.2's with .
Toss a coin 10 times to estimate its chance of heads . The number of heads is , with mean and variance (lesson 5.3.2). Compare two estimators.
- The share of heads, . Its mean is , so it is unbiased, and its variance is .
- Add one head and one tail, . Its mean is , pulled towards , so its bias is . Its variance is , smaller than 's.
| MSE of | bias of | MSE of | |
|---|---|---|---|
| 0.5 | 0.025 | 0 | 0.017361 |
| 0.3 | 0.021 | 0.0333 | 0.015694 |
| 0.1 | 0.009 | 0.0667 | 0.010694 |
Near , the small bias of buys a large cut in variance, and it has the smaller error. Near 0 its pull towards costs more than it saves, and the unbiased wins. Neither is better for every ; case study 4.6.5 shrank estimated returns for the same reason.
Try it
Each estimator is a function of , so LOTUS (lesson 5.3.1) gives its mean, variance and MSE by summing over the binomial pmf. Each line prints , the bias, the variance and the MSE: first, then .
The last line simulates 100,000 runs of 10 tosses with : the average squared errors are 0.021 and 0.0157.
The sample mean
The usual estimator of is the sample mean .
Rule: The sample mean
Unbiased for any distribution with a mean, by linearity (lesson 5.3.2). For independent draws the variances add and the factor comes out squared (lesson 5.7.2). So its MSE is , and its standard deviation is the standard error of lesson 5.8.2.
For the two rolls above, , the variance the table gave.
Being unbiased is not enough to make an estimator good. From three rolls of a die, here are three estimators of , all unbiased:
| estimator | mean | variance |
|---|---|---|
| the first roll, | 3.5 | |
| the middle value of the three | 3.5 | |
| the sample mean | 3.5 |
The middle value, the sample median, is centred on 3.5 because the die is symmetric. All three are centred correctly; scatters least, so it has the smallest MSE.
Try it
The array holds all 216 ordered triples of rolls, one per row. Each estimator is computed on every row.
.var() divides by 216 on purpose here. The rows are every possible outcome, each with probability , so this is the exact variance of a distribution, not an estimate from a sample.
Why the sample variance divides by
The variance is the mean squared deviation from . With unknown, the deviations are measured from instead. But is the centre of the sample itself, so the sample sits closer to than to . The squared deviations then come out too small on average.
By a table. A fair coin scores 0 or 1, so and . Take samples of ; the four outcomes are equally likely.
| sample | divide by | divide by | ||
|---|---|---|---|---|
| (0, 0) | 0 | 0 | 0 | 0 |
| (0, 1) | 0.5 | 0.5 | 0.25 | 0.5 |
| (1, 0) | 0.5 | 0.5 | 0.25 | 0.5 |
| (1, 1) | 1 | 0 | 0 | 0 |
| average |
Dividing by gives on average, half the true . Dividing by gives exactly .
By algebra. The sum of squared deviations from has a mean that can be worked out for any distribution with a finite variance:
- 1
- 2
- 3
- 4
Measuring from loses exactly one : the part that is 's own error. Dividing the sum by puts it back.
Rule: Sample variance
is unbiased for any distribution with a finite variance; has bias . The number is the degrees of freedom: the deviations from add to 0, so only of them are free to vary.
This is why lesson 5.5.2's sample variance and covariance, np.cov, and np.var with ddof=1 divide by , as case studies 3.1.4 and 3.2.5 did. For case study 3.1.4's ten months of X, np.var gives 0.002276 and ddof=1 gives 0.002528, larger by the factor .
Estimates of from samples of 5 normal draws. Dividing by centres the estimates on 1; dividing by centres them on 0.8. Either way most single samples fall below 1.
Try it
The loop prints the coin table above: each sample, , the sum of squares and the two divisions. The next line checks the first step of the algebra on the sample (2, 5, 3, 6) with : both sides are 10.
Then 100,000 seeded samples of 5. For normal draws the two averages are 0.7992 and 0.999, against 0.8 and 1. For die rolls they are 2.3291 and 2.9114, against and .
A known mean, the standard deviation, and higher moments
- A known mean. If is known, measure from and divide by : is unbiased, by the second step above. The pays for estimating .
- The standard deviation. is biased low even though is not, because the square root bends downwards (Jensen's inequality, lesson 5.7.1). For the coin with , is 0 or , so against . For 5 normal draws, . The bias fades as grows, and is used anyway.
- Skewness and kurtosis. Lesson 5.3.3's sample skewness and kurtosis divide by , and are biased in small samples.
bias=Falsein SciPy multiplies them by a correction factor, which reduces the bias but does not remove it.
Exponential draws have skewness 2 and excess kurtosis 6. In 100,000 seeded samples of 10, the sample skewness averages 0.974, or 1.155 with bias=False; the excess kurtosis averages 0.18, or 1.282. Higher moments need large samples.
Try it
The first line uses a known mean of 0, dividing by : the average is 1.0002. The second prints the coin's , then the average of over normal samples of 5.
Then case study 3.1.4's ten months, rebuilt from its seed, with both divisors and their ratio. The last lines are the skewness and kurtosis averages.
Unbiased is not always the most accurate
Divide the sum of squares by . For normal draws the MSE of each choice of is known exactly:
| divisor | MSE | MSE for , |
|---|---|---|
| 0.5 | ||
| 0.36 | ||
| 0.3333 |
The unbiased has the largest error of the three: its spread costs more than the others' bias. It stays the standard all the same, because the intervals and tests of lessons 5.8.2 and 5.8.3 are built on it. For large the three are almost equal.
Try it
The first line prints the three exact MSEs for from the table's formulas.
Then 200,000 seeded normal samples of 5. For each divisor the cell prints the average estimate and the average squared error, near the table's values.
Consistency
Bias and variance describe an estimator for one sample size. Consistency asks what happens as the sample grows: does the estimator close in on the truth?
Rule: Consistency
is the estimator from draws and (epsilon) any tolerance, however small. If its bias and its variance both tend to 0, it is consistent: Markov's inequality (lesson 5.7.1) applied to gives .
- The sample mean has MSE , so it is consistent: the law of large numbers of lesson 5.7.2.
- Both variance estimators are consistent. For normal draws with , the chance that misses by more than 0.1 is about 0.83, 0.48 and 0.02 for = 10, 100 and 1,000, in one seeded run. is biased for every , but its bias vanishes.
- The first draw alone is unbiased but not consistent. For draws, whatever is: the other draws are ignored.
- The mean of a Cauchy sample (the t with 1 degree of freedom, lesson 5.4.4) is not consistent. That distribution has no mean, and the average of Cauchy draws is again Cauchy. So for every .
| estimator | unbiased | consistent |
|---|---|---|
| yes | yes | |
| yes | yes | |
| no | yes | |
| alone | yes | no |
How the estimates of spread as the sample grows. Ninety percent of samples land inside the band, which closes in on 1; the divide-by- estimate's mean rises to meet it.
Try it
The loop draws 4,000 seeded normal samples of each size and prints the share of more than 0.1 from 1.
The next line is the first draw alone, , the same for every . Then the share of Cauchy means beyond 1, near 0.5 for every . Beside it is the exact chance that a mean of normal draws misses by more than 0.1, which falls to 0.0016.
Lesson 5.8.2 turns the spread of an estimator into an interval of plausible values, and case study 5.8.5 does this for a Sharpe ratio.
Common mistakes
- An estimate is one number; the estimator is a random variable. A different sample gives a different estimate, and its spread is part of the answer.
- Unbiased is not the same as accurate. The first roll alone is unbiased; compare estimators by their MSE.
- Divide by when the mean is estimated. With a known , divide by .
- is unbiased for , but is not unbiased for . An unbiased estimate of does not give an unbiased estimate of .
- Check the divisor.
np.varandnp.stddivide by unless givenddof=1;np.covdivides by . - Unbiased and consistent are different properties. alone is unbiased but not consistent; is consistent but biased.
Estimators: bias, variance and consistency
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
- An estimator is a random variable; its value for one sample is an estimate. Its distribution over samples is its sampling distribution.
- and . A little bias can buy a smaller MSE.
- is unbiased with variance ; its standard deviation is the standard error.
- , so divides by to be unbiased; dividing by has bias . With known, divide by . itself is biased low.
- Consistent: . Bias and variance tending to 0 is enough. alone and the Cauchy mean are not consistent.