Skip to content

Estimators: bias and variance

An estimate is one draw of a random variable, and the best estimator can trade a little off-centre for a lot less scatter.

Helps to know first
This topic

First, the picture

Take 4 points, average them, and fire the average at a target. Repeat 500 times, and watch where the shots land.

Off-centre or scattered

Estimating the centre (1, 1) of a round bell from 4 points, 500 times (seed 6200).

Estimator A: the average of each coordinate of 4 points. Each repeat takes a new sample and fires one shot.

shrink c
1.00
mean squared distance
–
bias²
–
variance
–
0.00 / 9.40 s
Describe this picture

Three panels that stay apart, side by side on a wide screen (on a phone, the first two above the third). The first, “the population”, is a round two-dimensional bell centred on a bull’s-eye at (1, 1), with spread 1 in each direction, drawn as shading that fades outward. The second, “one sample”, shows 4 points drawn from it and the estimate made from them, a ring labelled “estimate”. The third, “500 repeats”, shows the estimates from 500 seeded samples (seed 6200) as shots on a target. The clip runs two estimators in turn. Estimator A, the average of each coordinate, puts its shots in a cloud centred on the bull’s-eye. Then every shot is pulled 20 % towards (0, 0): estimator B, that average times 0.8, a tighter cloud centred at (0.8, 0.8). Readouts give the shrink factor and the mean squared distance from the shots to the bull’s-eye with its two parts, bias squared and variance, as measured: A 0.0009 + 0.5283 = 0.5292, B 0.0831 + 0.3381 = 0.4212. After the clip a slider, “Shrink factor c”, sets cc from 0.5 to 1.2 in steps of 0.05; the shots move, the readouts follow, and the caption gives the exact parts beside the measured ones.

An estimate is a draw

Somewhere there is a true value I want: the bull’s-eye. I only see a sample, and from it I compute a number that I hope is close. The true value is a parameter, written θ\theta; the rule that turns a sample into a guess is an estimator, written θ^\hat\theta. The hat means “estimated”.

The middle panel shows one sample and one estimate. Draw a new sample and you get a new estimate: an estimator is a random variable, with its own distribution over repeated samples. The third panel draws that distribution, and it is a different thing from both the population and the one sample. Keep the three apart.

Each coordinate of estimator A is the average of 4 draws with standard deviation 1. As in The law of large numbers, such an average has standard deviation 1/4=0.51/\sqrt4=0.5. So A’s shots scatter about 0.5 each way around the bull’s-eye. B’s shots are A’s times 0.8: they scatter only 0.4 each way, but around (0.8,0.8)(0.8,0.8).

Which is better? A is right on average but scattered. B is off-centre but tight. The readouts say B lands closer, on average: a mean squared distance of 0.4212 against A’s 0.5292, close to the exact 0.40 and 0.50.

Bias, variance and their sum

Two numbers describe an estimator’s cloud of shots. Its bias is how far the centre of the cloud is from the truth:

Bias{θ^}=E{θ^}−θ.\mathrm{Bias}\{\hat\theta\}=\mathbb{E}\{\hat\theta\}-\theta.

Its variance Var{θ^}\mathrm{Var}\{\hat\theta\} is how widely the shots scatter around their own centre. An estimator with bias 0 is unbiased.

What I care about is how far the shots land from the truth. The mean squared error measures it:

MSE{θ^}=E{(θ^−θ)2}.\mathrm{MSE}\{\hat\theta\}=\mathbb{E}\{(\hat\theta-\theta)^2\}.

Write θ^−θ\hat\theta-\theta as (θ^−E{θ^})+(E{θ^}−θ)(\hat\theta-\mathbb{E}\{\hat\theta\})+(\mathbb{E}\{\hat\theta\}-\theta): a scatter part with mean 0, plus the fixed bias. Square and take the mean. The cross term has a factor with mean 0, so it drops out:

MSE{θ^}=Bias{θ^}2+Var{θ^}.\mathrm{MSE}\{\hat\theta\}=\mathrm{Bias}\{\hat\theta\}^2+\mathrm{Var}\{\hat\theta\}.

For one coordinate of the target: A has bias 0 and variance 0.250.25, so its MSE is 0.250.25. B has bias −0.2-0.2 and variance 0.64×0.25=0.160.64\times0.25=0.16, so its MSE is 0.04+0.16=0.200.04+0.16=0.20. The target adds the two coordinates, so its readouts are twice these: 0.500.50 for A, and 0.08+0.32=0.400.08+0.32=0.40 for B.

Why divide by n−1n-1

Describing data divided the squared deviations by n−1n-1 to get s2s^2. Here is an exact count that shows why.

Why divide by n − 1

Every sample of two from 0, 3 and 6, and the two ways to average their spread.

Draw two values from 0, 3 and 6, with replacement: nine samples in all, each with its sum of squared deviations from its own mean.

average, ÷ n
–
average, ÷ (n − 1)
–
true variance
6

Predict first. Over all nine samples, what does "divide by n" average to?

0.00 / 10.40 s
Describe this picture

The population is the three numbers 0, 3 and 6, each equally likely: mean 3, variance 6. All nine samples of two values, drawn with replacement, are listed in a small table with their sums of squared deviations from their own mean: 0, 4.5, 18, 4.5, 0, 4.5, 18, 4.5, 0. Before the clip a question asks what the average of “divide by nn” will be over the nine samples: 6, 3 or 4.5. A tap picks one and starts the clip. In the clip the nine values drop as dots onto two rows on one scale from 0 to 20, with a dashed line at the true variance, 6: divided by 2 they average 3; divided by 1 they average 6, the true variance. Your guess is then drawn as a dotted marker on the first row. Readouts give the two averages and the true variance. There is no control after the clip.

The sum of squared deviations averages 6 over the nine samples. Divide it by n=2n=2 and the estimate averages 3, half the truth. Divide by n−1=1n-1=1 and it averages 6, exactly the truth.

The reason holds for every sample size. The deviations are measured from the sample’s own mean xˉ\bar x, which sits in the middle of the sample and so is closer to the points than the true mean μX\mu_X is. Exactly how much closer is an identity:

∑k(Xk−Xˉn)2=∑k(Xk−μX)2−n(Xˉn−μX)2.\sum_k(X_k-\bar X_n)^2=\sum_k(X_k-\mu_X)^2-n(\bar X_n-\mu_X)^2.

Here the XkX_k are the draws as random variables, before the sample is seen. Take means. The first sum has mean nσX2n\sigma_X^2. The average Xˉn\bar X_n has variance σX2/n\sigma_X^2/n, so the last term has mean σX2\sigma_X^2. What is left is (n−1)σX2(n-1)\sigma_X^2, so

E{s2}=E{1n−1∑k=1n(Xk−Xˉn)2}=σX2.\mathbb{E}\{s^2\}=\mathbb{E}\Big\{\frac{1}{n-1}\sum_{k=1}^{n}(X_k-\bar X_n)^2\Big\}=\sigma_X^2.

With divisor nn the mean is n−1nσX2\frac{n-1}{n}\sigma_X^2, a bias of −σX2/n-\sigma_X^2/n. For n=10n=10 that is −σX2/10-\sigma_X^2/10.

Watch out

The divisor n−1n-1 is not a convention. It makes s2s^2 right on average. But “right on average” is only one way to judge an estimator, as the next section shows.

Shrinking: a little bias for less scatter

Estimator B multiplied the average by a shrink factor cc, here 0.8. In general, for the average Xˉn\bar X_n of nn draws,

MSE{cXˉn}=c2σX2n+(c−1)2μX2.\mathrm{MSE}\{c\bar X_n\}=c^2\frac{\sigma_X^2}{n}+(c-1)^2\mu_X^2.

The first term is the variance, which shrinks with cc; the second is the bias squared, which grows as cc moves away from 1. Their sum is smallest at

c=μX2μX2+σX2/n.c=\frac{\mu_X^2}{\mu_X^2+\sigma_X^2/n}.

For the target, μX=1\mu_X=1, σX=1\sigma_X=1 and n=4n=4, so the best factor is 1/1.25=0.81/1.25=0.8. After the clip, drag cc and watch the total: 0.6250.625 at c=0.5c=0.5, 0.400.40 at 0.80.8, 0.500.50 at 1 and 0.800.80 at 1.21.2, a U with its bottom at 0.8.

There is a catch. The best cc depends on μX\mu_X, the very thing being estimated. In practice it is chosen from earlier data or a rule, and the gain is real only when the guess is reasonable. The lesson stands, though: an unbiased estimator is not always the best one.

Consistency

An estimator is consistent if it settles on the truth as the sample grows; an MSE that falls to 0 is enough to show it. The average Xˉn\bar X_n is unbiased with variance σX2/n\sigma_X^2/n, so its MSE falls to 0. With σX=2\sigma_X=2 and n=16n=16 it is already 4/16=0.254/16=0.25.

Worked example

1. The nine samples. Over the nine samples the divisor-nn estimate averages 54/9/2=354/9/2=3, which is σX2/2\sigma_X^2/2, half the truth. The divisor-(n−1)(n-1) estimate averages 6=σX26=\sigma_X^2.

2. Shrinking a mean. With μX=1\mu_X=1, σX=1\sigma_X=1 and n=4n=4, the average Xˉ\bar X has MSE 0.250.25. The estimate 0.8Xˉ0.8\bar X has bias −0.2-0.2, variance 0.160.16 and MSE 0.200.20.

3. Three divisors for a variance. Take bell-shaped data with σX2=1\sigma_X^2=1 and n=5n=5, and divide the sum of squared deviations by 4, 5 or 6:

DivisorBiasVarianceMean squared error
400.50.5
5−0.20.320.36
6−0.33330.22220.3333

The unbiased divisor, 4, has the largest error. Dividing by 6 is biased low but lands closest on average. Which one to use depends on what you need: right on average, or close on average.

Where you’ll meet this

Calibration. A sensor is calibrated by averaging repeated readings of a known reference; the bias of the average is the calibration error, and its variance falls as 1/n1/n.

Regression. Shrinkage estimators such as ridge regression pull fitted coefficients towards zero: a little bias for much less scatter, the trade of the target.

Experiments. Every A/B test reports an estimate, and its standard error is the square root of the estimator’s variance, the subject of Confidence intervals.

In signal processing · bias and variance of a spectrum

The periodogram estimates a spectrum, and more data does not steady it: its variance does not shrink, so it is not consistent. Averaging segments trades resolution, a bias, for less variance. The periodogram and Averaged periodograms: Bartlett and Welch in the signal processing course make the trade.

Where this leads · ridge is shrinkage

Ridge regression adds a penalty that shrinks the solution towards zero, the matrix form of the factor cc. The pseudo-inverse in the linear algebra course shows the algebra.

Reference card

QuantityFormulaNotes
Estimatorθ^\hat\theta, a function of the samplea random variable
BiasBias{θ^}=E{θ^}−θ\mathrm{Bias}\{\hat\theta\}=\mathbb{E}\{\hat\theta\}-\theta0: unbiased
Mean squared errorMSE{θ^}=E{(θ^−θ)2}\mathrm{MSE}\{\hat\theta\}=\mathbb{E}\{(\hat\theta-\theta)^2\}=Bias2+Var=\mathrm{Bias}^2+\mathrm{Var}
Sample varianceE{s2}=σX2\mathbb{E}\{s^2\}=\sigma_X^2 with divisor n−1n-1divisor nn: n−1nσX2\frac{n-1}{n}\sigma_X^2
Shrinking the meanMSE{cXˉn}=c2σX2/n+(c−1)2μX2\mathrm{MSE}\{c\bar X_n\}=c^2\sigma_X^2/n+(c-1)^2\mu_X^2best c=μX2/(μX2+σX2/n)c=\mu_X^2/(\mu_X^2+\sigma_X^2/n)
ConsistentMSE falls to 0 as nn growsXˉn\bar X_n: σX2/n\sigma_X^2/n

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look