SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 5.8.1 Estimators: bias, variance and consistencyConcept · 35 min
      2. 5.8.2 Sampling distributions and confidence intervalsConcept · 35 min
      3. 5.8.3 Hypothesis testsConcept · 30 min
      4. 5.8.4 Practice set: statistical inferencePractice set · 25 min
      5. 5.8.5 Case study: is this Sharpe ratio significant?Case study · 35 min

Level 5, Probability and statistics 5.8 Statistical inference Lesson 1 of 5

ConceptLesson 5.8.1 in Level 5, Probability and statistics. About 35 minutes.

Estimators: bias, variance and consistency

An estimator is a random variable

A distribution has fixed numbers that describe it, such as its mean μ\mu, its variance σ2\sigma^2 or a coin's chance of heads pp. Such a number is a parameter, written θ\theta (theta) in general. In practice θ\theta is unknown, and data are used to guess it.

The data are a sample X1,…,XnX_1, \ldots, X_n: nn independent draws, each with the same distribution. This is often shortened to i.i.d., independent and identically distributed.

Rule: Estimator and estimate

θ^=g(X1,…,Xn)\hat{\theta} = g(X_1, \ldots, X_n)

An estimator is a rule gg 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 x1,…,xnx_1, \ldots, x_n is an estimate, a single number.

Take a fair die, whose mean μ=3.5\mu = 3.5 we pretend not to know, and the estimator Xˉ=12(X1+X2)\bar{X} = \frac{1}{2}(X_1 + X_2) from two rolls. The 36 equally likely pairs give 11 possible values:

xˉ\bar{x}11.522.533.544.555.56
pairs12345654321

This is the two-dice total of lesson 5.6.3, halved. Its mean is 3.53.5, the true μ\mu, and its variance is 3524≈1.4583\frac{35}{24} \approx 1.4583.

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 xˉ\bar{x} 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.

⌘/Ctrl + Enter runs the cell

Bias, variance and mean squared error

A good estimator lands close to θ\theta. Three numbers measure how close: where it is centred, how widely it scatters, and the two combined.

Rule: Bias, variance and MSE

bias⁡(θ^)=E[θ^]−θMSE⁡(θ^)=E[(θ^−θ)2]=Var⁡(θ^)+bias⁡(θ^)2\begin{gathered} \operatorname{bias}(\hat{\theta}) = \mathbb{E}[\hat{\theta}] - \theta \\[4pt] \operatorname{MSE}(\hat{\theta}) = \mathbb{E}\big[(\hat{\theta} - \theta)^2\big] \\[4pt] = \operatorname{Var}(\hat{\theta}) + \operatorname{bias}(\hat{\theta})^2 \end{gathered}

An estimator is unbiased when its bias is 0 for every value of θ\theta. The mean squared error (MSE) is in θ\theta's units squared; its square root is in θ\theta's units. The split is lesson 5.3.2's E[Y2]=Var⁡(Y)+(E[Y])2\mathbb{E}[Y^2] = \operatorname{Var}(Y) + (\mathbb{E}[Y])^2 with Y=θ^−θY = \hat{\theta} - \theta.

Toss a coin 10 times to estimate its chance of heads pp. The number of heads HH is Bin⁡(10,p)\operatorname{Bin}(10, p), with mean 10p10p and variance 10p(1−p)10p(1 - p) (lesson 5.3.2). Compare two estimators.

  • The share of heads, p^=H10\hat{p} = \frac{H}{10}. Its mean is pp, so it is unbiased, and its variance is p(1−p)10\frac{p(1 - p)}{10}.
  • Add one head and one tail, p~=H+112\tilde{p} = \frac{H + 1}{12}. Its mean is 10p+112\frac{10p + 1}{12}, pulled towards 12\frac{1}{2}, so its bias is 1−2p12\frac{1 - 2p}{12}. Its variance is 10p(1−p)144\frac{10p(1 - p)}{144}, smaller than p^\hat{p}'s.
ppMSE of p^\hat{p}bias of p~\tilde{p}MSE of p~\tilde{p}
0.50.02500.017361
0.30.0210.03330.015694
0.10.0090.06670.010694

Near 12\frac{1}{2}, the small bias of p~\tilde{p} buys a large cut in variance, and it has the smaller error. Near 0 its pull towards 12\frac{1}{2} costs more than it saves, and the unbiased p^\hat{p} wins. Neither is better for every pp; case study 4.6.5 shrank estimated returns for the same reason.

Try it

Each estimator is a function of HH, so LOTUS (lesson 5.3.1) gives its mean, variance and MSE by summing over the binomial pmf. Each line prints pp, the bias, the variance and the MSE: p^\hat{p} first, then p~\tilde{p}.

The last line simulates 100,000 runs of 10 tosses with p=0.3p = 0.3: the average squared errors are 0.021 and 0.0157.

⌘/Ctrl + Enter runs the cell

The sample mean

The usual estimator of μ\mu is the sample mean Xˉ=1n(X1+⋯+Xn)\bar{X} = \frac{1}{n}(X_1 + \cdots + X_n).

Rule: The sample mean

E[Xˉ]=μVar⁡(Xˉ)=σ2n\begin{gathered} \mathbb{E}[\bar{X}] = \mu \\[4pt] \operatorname{Var}(\bar{X}) = \frac{\sigma^2}{n} \end{gathered}

Unbiased for any distribution with a mean, by linearity (lesson 5.3.2). For independent draws the nn variances add and the factor 1n\frac{1}{n} comes out squared (lesson 5.7.2). So its MSE is σ2n\frac{\sigma^2}{n}, and its standard deviation σn\frac{\sigma}{\sqrt{n}} is the standard error of lesson 5.8.2.

For the two rolls above, σ2n=35/122=3524\frac{\sigma^2}{n} = \frac{35/12}{2} = \frac{35}{24}, 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 μ\mu, all unbiased:

estimatormeanvariance
the first roll, X1X_13.53512≈2.9167\frac{35}{12} \approx 2.9167
the middle value of the three3.5203108≈1.8796\frac{203}{108} \approx 1.8796
the sample mean Xˉ\bar{X}3.53536≈0.9722\frac{35}{36} \approx 0.9722

The middle value, the sample median, is centred on 3.5 because the die is symmetric. All three are centred correctly; Xˉ\bar{X} 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 1216\frac{1}{216}, so this is the exact variance of a distribution, not an estimate from a sample.

⌘/Ctrl + Enter runs the cell

Why the sample variance divides by n−1n - 1

The variance σ2\sigma^2 is the mean squared deviation from μ\mu. With μ\mu unknown, the deviations are measured from Xˉ\bar{X} instead. But Xˉ\bar{X} is the centre of the sample itself, so the sample sits closer to Xˉ\bar{X} than to μ\mu. The squared deviations then come out too small on average.

By a table. A fair coin scores 0 or 1, so μ=12\mu = \frac{1}{2} and σ2=14\sigma^2 = \frac{1}{4}. Take samples of n=2n = 2; the four outcomes are equally likely.

samplexˉ\bar{x}∑(xi−xˉ)2\sum (x_i - \bar{x})^2divide by n=2n = 2divide by n−1=1n - 1 = 1
(0, 0)0000
(0, 1)0.50.50.250.5
(1, 0)0.50.50.250.5
(1, 1)1000
average18\frac{1}{8}14\frac{1}{4}

Dividing by nn gives 18\frac{1}{8} on average, half the true 14\frac{1}{4}. Dividing by n−1n - 1 gives exactly 14\frac{1}{4}.

By algebra. The sum of squared deviations from Xˉ\bar{X} has a mean that can be worked out for any distribution with a finite variance:

  1. 1

    ∑i(Xi−Xˉ)2=∑i(Xi−μ)2−n(Xˉ−μ)2\sum_i (X_i - \bar{X})^2 = \sum_i (X_i - \mu)^2 - n(\bar{X} - \mu)^2

  2. 2

    E[∑i(Xi−μ)2]=nσ2\mathbb{E}\big[\sum_i (X_i - \mu)^2\big] = n\sigma^2

  3. 3

    E[n(Xˉ−μ)2]=σ2\mathbb{E}\big[n(\bar{X} - \mu)^2\big] = \sigma^2

  4. 4

    E[∑i(Xi−Xˉ)2]=(n−1)σ2\mathbb{E}\big[\sum_i (X_i - \bar{X})^2\big] = (n - 1)\sigma^2

Measuring from Xˉ\bar{X} loses exactly one σ2\sigma^2: the part that is Xˉ\bar{X}'s own error. Dividing the sum by n−1n - 1 puts it back.

Rule: Sample variance

s2=1n−1∑i(Xi−Xˉ)2E[s2]=σ2σ^2=1n∑i(Xi−Xˉ)2E[σ^2]=n−1n σ2\begin{gathered} s^2 = \frac{1}{n - 1}\textstyle\sum_i (X_i - \bar{X})^2 \\[4pt] \mathbb{E}[s^2] = \sigma^2 \\[8pt] \hat{\sigma}^2 = \frac{1}{n}\textstyle\sum_i (X_i - \bar{X})^2 \\[4pt] \mathbb{E}[\hat{\sigma}^2] = \frac{n - 1}{n}\,\sigma^2 \end{gathered}

s2s^2 is unbiased for any distribution with a finite variance; σ^2\hat{\sigma}^2 has bias −σ2n-\frac{\sigma^2}{n}. The number n−1n - 1 is the degrees of freedom: the nn deviations from Xˉ\bar{X} add to 0, so only n−1n - 1 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 n−1n - 1, 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 109\frac{10}{9}.

Estimates of σ2=1\sigma^2 = 1 from samples of 5 normal draws. Dividing by n−1n - 1 centres the estimates on 1; dividing by nn centres them on 0.8. Either way most single samples fall below 1.

Try it

The loop prints the coin table above: each sample, xˉ\bar{x}, 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 μ=3.5\mu = 3.5: 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 45×3512≈2.3333\frac{4}{5} \times \frac{35}{12} \approx 2.3333 and 3512≈2.9167\frac{35}{12} \approx 2.9167.

⌘/Ctrl + Enter runs the cell

A known mean, the standard deviation, and higher moments

  • A known mean. If μ\mu is known, measure from μ\mu and divide by nn: 1n∑i(Xi−μ)2\frac{1}{n}\sum_i (X_i - \mu)^2 is unbiased, by the second step above. The n−1n - 1 pays for estimating μ\mu.
  • The standard deviation. s=s2s = \sqrt{s^2} is biased low even though s2s^2 is not, because the square root bends downwards (Jensen's inequality, lesson 5.7.1). For the coin with n=2n = 2, ss is 0 or 0.5\sqrt{0.5}, so E[s]≈0.3536\mathbb{E}[s] \approx 0.3536 against σ=0.5\sigma = 0.5. For 5 normal draws, E[s]≈0.94σ\mathbb{E}[s] \approx 0.94\sigma. The bias fades as nn grows, and ss is used anyway.
  • Skewness and kurtosis. Lesson 5.3.3's sample skewness and kurtosis divide by nn, and are biased in small samples. bias=False in 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 n=5n = 5: the average is 1.0002. The second prints the coin's E[s]\mathbb{E}[s], then the average of ss 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.

⌘/Ctrl + Enter runs the cell

Unbiased is not always the most accurate

Divide the sum of squares ∑i(Xi−Xˉ)2\sum_i (X_i - \bar{X})^2 by dd. For normal draws the MSE of each choice of dd is known exactly:

divisor ddMSEMSE for n=5n = 5, σ=1\sigma = 1
n−1n - 12σ4n−1\frac{2\sigma^4}{n - 1}0.5
nn(2n−1)σ4n2\frac{(2n - 1)\sigma^4}{n^2}0.36
n+1n + 12σ4n+1\frac{2\sigma^4}{n + 1}0.3333

The unbiased s2s^2 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 nn the three are almost equal.

Try it

The first line prints the three exact MSEs for n=5n = 5 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.

⌘/Ctrl + Enter runs the cell

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

lim⁡n→∞P(∣θ^n−θ∣>ε)=0for every ε>0\begin{gathered} \lim_{n \to \infty} P\big(\lvert \hat{\theta}_n - \theta \rvert > \varepsilon\big) = 0 \\[4pt] \text{for every } \varepsilon > 0 \end{gathered}

θ^n\hat{\theta}_n is the estimator from nn draws and ε\varepsilon (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 (θ^n−θ)2(\hat{\theta}_n - \theta)^2 gives P(∣θ^n−θ∣≥ε)≤MSE⁡ε2P(\lvert \hat{\theta}_n - \theta \rvert \ge \varepsilon) \le \frac{\operatorname{MSE}}{\varepsilon^2}.

  • The sample mean has MSE σ2n→0\frac{\sigma^2}{n} \to 0, so it is consistent: the law of large numbers of lesson 5.7.2.
  • Both variance estimators are consistent. For normal draws with σ2=1\sigma^2 = 1, the chance that s2s^2 misses by more than 0.1 is about 0.83, 0.48 and 0.02 for nn = 10, 100 and 1,000, in one seeded run. σ^2\hat{\sigma}^2 is biased for every nn, but its bias −σ2n-\frac{\sigma^2}{n} vanishes.
  • The first draw alone is unbiased but not consistent. For N(μ,1)\mathcal{N}(\mu, 1) draws, P(∣X1−μ∣>0.1)=0.9203P(\lvert X_1 - \mu \rvert > 0.1) = 0.9203 whatever nn 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 nn Cauchy draws is again Cauchy. So P(∣Xˉ∣>1)=0.5P(\lvert \bar{X} \rvert > 1) = 0.5 for every nn.
estimatorunbiasedconsistent
Xˉ\bar{X}yesyes
s2s^2yesyes
σ^2\hat{\sigma}^2noyes
X1X_1 aloneyesno

How the estimates of σ2=1\sigma^2 = 1 spread as the sample grows. Ninety percent of samples land inside the band, which closes in on 1; the divide-by-nn estimate's mean n−1n\frac{n - 1}{n} rises to meet it.

Try it

The loop draws 4,000 seeded normal samples of each size and prints the share of s2s^2 more than 0.1 from 1.

The next line is the first draw alone, 2N(−0.1)2N(-0.1), the same for every nn. Then the share of Cauchy means beyond 1, near 0.5 for every nn. Beside it is the exact chance that a mean of normal draws misses by more than 0.1, which falls to 0.0016.

⌘/Ctrl + Enter runs the cell

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

  1. 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.
  2. Unbiased is not the same as accurate. The first roll alone is unbiased; compare estimators by their MSE.
  3. Divide by n−1n - 1 when the mean is estimated. With a known μ\mu, divide by nn.
  4. s2s^2 is unbiased for σ2\sigma^2, but ss is not unbiased for σ\sigma. An unbiased estimate of θ\theta does not give an unbiased estimate of θ\sqrt{\theta}.
  5. Check the divisor. np.var and np.std divide by nn unless given ddof=1; np.cov divides by n−1n - 1.
  6. Unbiased and consistent are different properties. X1X_1 alone is unbiased but not consistent; σ^2\hat{\sigma}^2 is consistent but biased.

Estimators: bias, variance and consistency

0 of 12 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 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, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for 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 θ^=g(X1,…,Xn)\hat{\theta} = g(X_1, \ldots, X_n) is a random variable; its value for one sample is an estimate. Its distribution over samples is its sampling distribution.
  • bias⁡=E[θ^]−θ\operatorname{bias} = \mathbb{E}[\hat{\theta}] - \theta and MSE⁡=E[(θ^−θ)2]=Var⁡(θ^)+bias⁡2\operatorname{MSE} = \mathbb{E}[(\hat{\theta} - \theta)^2] = \operatorname{Var}(\hat{\theta}) + \operatorname{bias}^2. A little bias can buy a smaller MSE.
  • Xˉ\bar{X} is unbiased with variance σ2n\frac{\sigma^2}{n}; its standard deviation σn\frac{\sigma}{\sqrt{n}} is the standard error.
  • E[∑i(Xi−Xˉ)2]=(n−1)σ2\mathbb{E}\big[\sum_i (X_i - \bar{X})^2\big] = (n - 1)\sigma^2, so s2s^2 divides by n−1n - 1 to be unbiased; dividing by nn has bias −σ2n-\frac{\sigma^2}{n}. With μ\mu known, divide by nn. ss itself is biased low.
  • Consistent: P(∣θ^n−θ∣>ε)→0P(\lvert \hat{\theta}_n - \theta \rvert > \varepsilon) \to 0. Bias and variance tending to 0 is enough. X1X_1 alone and the Cauchy mean are not consistent.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.