Estimators, bias and variance
An estimator is a recipe that turns a sample into a guess. Two recipes can target the same quantity and still behave very differently from sample to sample. This chapter measures that behaviour the way the 2020 notebook did — by simulation — and compares it with the theory.
§1.1Coursework A1 Q4
Midrange or mean?
With a sample of 20 from a normal distribution, one suggestion was to estimate μ by the midrange, the average of the smallest and largest values; the other was to use the sample mean. Both are unbiased by symmetry, so the question is spread. The notebook drew 100 samples with set.seed(2529) and compared
The port re-implements R’s random number generator, so the default settings below replay those same 2,000 normal draws (identical to the last bit or two) and print the 2020 results exactly.
Above about 60 000 draws the simulation runs in a Web Worker.
Midrange bias
0.043088
Midrange variance
0.158578
Mean bias
-0.020101
Mean variance
0.069188
theory σ²/n = 0.05
- Midrange (min + max) / 2
- Sample mean
- True mean μ = 0
Show the numbers as a table
| estimator | bias | variance | MSE | median | IQR (hinges) |
|---|---|---|---|---|---|
| Midrange | 0.043088 | 0.158578 | 0.158849 | 0.0268 | 0.6123 |
| Sample mean | -0.020101 | 0.069188 | 0.068900 | -0.0159 | 0.3598 |
§1.2Coursework A1 Q3
Method of moments against maximum likelihood
For the method of moments matches to the sample mean, while the likelihood for is maximised at the largest observation:
Mean squared error splits into variance plus squared bias,, giving for the MME and for the MLE. Multiplying the MLE by minimises MSE among multiples of it.
Try n = 1: a single observation, as in part (a) of the question. The MLE is then just X itself, biased downwards by half.
Solid black line: the true θ. Dashed line: the average of the simulated estimates. The ± after each simulated MSE is its Monte Carlo standard error, sd((θ̂ − θ)²) / √R.
Show simulated and theoretical moments
| estimator | mean (sim) | mean (theory) | variance (sim) | MSE (sim) | ± MCSE | MSE (theory) |
|---|---|---|---|---|---|---|
| Method of moments 2X̄ | 3.0300 | 3.0000 | 0.28760 | 0.28835 | 0.00906 | 0.30000 |
| Maximum likelihood max(Xᵢ) | 2.7367 | 2.7273 | 0.05774 | 0.12703 | 0.00517 | 0.13636 |
| Scaled MLE 1.091·max(Xᵢ) | 2.9855 | 3.0000 | 0.06872 | 0.06889 | 0.00345 | 0.07438 |
§1.3Coursework A3 Q3
A Bayesian estimate
Assignment 3 swapped the frequentist view for a prior. With data from and the prior , the posterior is proportional to , which is
Data are drawn from f(x | β) = β²x e−βx, a Gamma(2, β) distribution, as the sum of two exponential draws. Set n = 0 to see the prior on its own.
Posterior
Γ(21, 12.77)
shape 2n + 1, rate Σx + 1
Posterior mean
1.645
sd 0.359
95% credible interval
(1.02, 2.42)
MLE 2n / Σx
1.699
true β = 1.5
- Prior e^(−β)
- Posterior
- MLE
- True β