Properties of estimators — exam-style exercises with the scooter fleet, the best-guessing maximum, the speedometer and Cramér–Rao (and the “more efficient” one that wasn’t)

In the EC2 mock exam we did in class I was asked to decide which of two variance estimators was more efficient, and I compared their variances: I picked the unbiased one and got zero for the part. The question said “by the mean squared error criterion”, and the other one, the biased one, had a smaller MSE. I had read it, but in my head “efficient” meant “the one with less variance” and I did not look again. Two points for one word. This article is so that in the real one you read the criterion before comparing.

These are three chained exercises like those in the ME1 EC2 (one context per exercise and parts that build on the previous one), with the rental scooter fleet in Las Palmas as the thread, plus a bonus. Before you start, it helps to have the theory, the proofs and the practice of properties of estimators, and point estimation, because here you first have to derive the estimator.

How to use this article

  1. Do the exercises with the exam in mind. In the ME1 EC2 you have 4 hours for 50 points, with RStudio and the data open. These three exercises add up to 40 points plus a 2.5-point bonus: give them about 3 hours.
  2. Paper for what is proved, R for what is computed. Unbiasedness, MSE, bound and consistency on paper; the estimates and the simulations that check them in R, with 2 decimals as the exam asks. Keep the code in a script: at the end you have to upload the .R file with the code for each exercise.
  3. Read the criterion. “More efficient” by variances (between unbiased estimators) or by MSE is not the same thing. And plain “efficient” means reaching the Cramér–Rao bound.
  4. Mark yourself with the criteria. Each solution comes with “How it is marked” and a split of the points. It is a guide, mine: not the official marking scheme.
  5. Finish with the cheat sheet and “For your script”. The cheat sheet only has results (that is what you can take in, handwritten: two sheets, both sides, in the EC2) and “For your script” is the topic’s code, ready for your .R file. If a proof gets stuck, the proofs have the step by step.

Exercise 1: the time between two rentals (10 points)

The scooter company wants to know how long a scooter takes to be rented again once someone leaves it in the street. The time X, in minutes, between two rentals of the same scooter is modelled with the density

f(x∣θ)=xθ2 e−x/θ,x>0, θ>0 f(x\mid\theta) = \frac{x}{\theta^2}\,e^{-x/\theta}, \qquad x > 0,\ \theta > 0

These are 15 times measured around campus:

gap <- c(10.1, 18.3, 8.3, 17.1, 29.5, 21.2, 12.3, 6.4, 19.9, 6.2, 24.1, 10.6, 11.5, 4.8, 22.2)
  1. (2 points) Compute E(X) and Var(X), identifying the distribution of X, and get the method of moments estimator of θ, θ~ \tilde\theta .
  2. (3 points) Get the maximum likelihood estimator, θ^ \hat\theta , and check that it is a maximum.
  3. (2 points) Prove that θ^ \hat\theta is unbiased, compute its variance and prove that it is consistent.
  4. (2 points) Prove that θ^ \hat\theta is efficient.
  5. (1 point) Give the estimate of θ from the data and its standard error.

Exercise 2: the serial numbers at Las Canteras (15 points)

Another scooter company also spreads its fleet around the city. Its scooters are numbered from 1 to θ and, as in the theory, the number of any one of them is modelled as a uniform(0, θ). These are the numbers of 10 of that company’s scooters seen along the Las Canteras promenade:

canteras <- c(1715, 1479, 2351, 1621, 264, 1262, 2929, 991, 2677, 1254)

Recall (no need to prove it): for X(n)=max⁡(Xi) X_{(n)} = \max(X_i) , E(X(n))=nn+1θ E(X_{(n)}) = \frac{n}{n+1}\theta and E(X(n)2)=nn+2θ2 E(X_{(n)}^2) = \frac{n}{n+2}\theta^2 .

  1. (2 points) Compute from the data the estimates of θ with 2Xˉ 2\bar X , with X(n) X_{(n)} and with n+1nX(n) \frac{n+1}{n}X_{(n)} .
  2. (3 points) Among all estimators of the form cX(n) cX_{(n)} , with c > 0, find the value of c that minimises the MSE and the value of that minimum MSE.
  3. (3 points) Compute the bias of the estimator from part 2, T=c∗X(n) T = c^* X_{(n)} , and compare its MSE with that of n+1nX(n) \frac{n+1}{n}X_{(n)} . Which is more efficient by the MSE criterion?
  4. (3 points) Prove that T is consistent.
  5. (2 points) With R, simulate 10,000 samples of 10 scooters from a fleet of θ = 3000 and compute the MSE of the four estimators (the three from part 1 and T). Compare them with their formulas.
  6. (2 points) Give the estimate of θ with T and explain why a biased estimator can beat an unbiased one.

Exercise 3: the speedometer error (15 points)

The scooters have a speedometer that is not exact. The error X (speed shown minus real speed, in km/h) follows a normal N(0,σ) N(0, \sigma) : on average it is not wrong (μ = 0, known), but we do not know how much it strays. These are the errors of 12 scooters measured on a test bench:

error <- c(-1.18, 0.08, -1.76, -0.25, -2.80, -0.18, 1.24, 1.79, -1.64, -0.56, -1.40, 0.05)

We call the parameter v=σ2 v = \sigma^2 .

  1. (3 points) Get the maximum likelihood estimator of v, v^ \hat v , and check that it is a maximum.
  2. (3 points) Prove that v^ \hat v is unbiased and compute its variance. (Hint: identify the distribution of ∑Xi2/σ2 \sum X_i^2/\sigma^2 .)
  3. (3 points) Prove that v^ \hat v is efficient.
  4. (2 points) A classmate suggests using the sample variance S2 S^2 , “which is unbiased”. Compare its MSE with that of v^ \hat v . Which is more efficient? Why?
  5. (2 points) Compute from the data v^ \hat v , S2 S^2 and the maximum likelihood estimate of σ. Justify the last one.
  6. (2 points) With R, check with 10,000 simulations (σ = 1.5) the variances of v^ \hat v and S2 S^2 .

Bonus (2.5 points)

At night trips are longer. These are the durations, in minutes, of 25 night trips, assumed exponential(λ):

night <- c(17.3, 8.2, 7.0, 2.1, 24.8, 10.9, 1.1, 65.4, 9.7, 0.4, 6.4, 48.6, 14.9,
           12.3, 19.5, 0.2, 50.7, 2.5, 34.3, 27.9, 12.8, 75.3, 13.5, 26.0, 48.2)
  1. (1 point) Compute the MLE of λ and its asymptotic variance, with the formula and with optim.
  2. (1 point) Give the standard error and interpret it.
  3. (0.5 points) Give the unbiased estimate of λ.

Solutions

Exercise 1

Part 1. The density is that of a gamma with shape 2 and scale θ (rate 1/θ). With the rule ∫0∞xa−1e−x/θdx=Γ(a) θa \int_0^\infty x^{a-1}e^{-x/\theta}dx = \Gamma(a)\,\theta^a :

E(X)=1θ2∫0∞x2e−x/θdx=Γ(3) θ3θ2=2θ,E(X2)=Γ(4) θ4θ2=6θ2 E(X) = \frac{1}{\theta^2}\int_0^\infty x^2 e^{-x/\theta}dx = \frac{\Gamma(3)\,\theta^3}{\theta^2} = 2\theta, \qquad E(X^2) = \frac{\Gamma(4)\,\theta^4}{\theta^2} = 6\theta^2
Var(X)=6θ2−(2θ)2=2θ2 \text{Var}(X) = 6\theta^2 – (2\theta)^2 = 2\theta^2

Setting E(X)=2θ E(X) = 2\theta equal to Xˉ \bar X : θ~=Xˉ/2 \tilde\theta = \bar X/2 .

Why spot the gamma instead of integrating by parts. The integral of x2e−x/θ x^2e^{-x/\theta} can be done by parts, but it takes two rounds, and three more for E(X2) E(X^2) : in the exam, a lot of time and a sign lost somewhere. If you see “a power of x times an exponential”, the gamma rule gives each expectation in one line. And the method of moments always goes in this order: E(X) E(X) as a function of θ, set it equal to Xˉ \bar X , and solve.

Part 2. With ℓ(θ)=∑log⁡xi−2nlog⁡θ−1θ∑xi \ell(\theta) = \sum\log x_i – 2n\log\theta – \frac{1}{\theta}\sum x_i :

ℓ′(θ)=−2nθ+∑xiθ2=0⟹θ^=∑xi2n=Xˉ2 \ell'(\theta) = -\frac{2n}{\theta} + \frac{\sum x_i}{\theta^2} = 0 \quad\Longrightarrow\quad \hat\theta = \frac{\sum x_i}{2n} = \frac{\bar X}{2}

Second derivative: ℓ′′(θ)=2nθ2−2∑xiθ3 \ell''(\theta) = \frac{2n}{\theta^2} – \frac{2\sum x_i}{\theta^3} . At θ^ \hat\theta , since ∑xi=2nθ^ \sum x_i = 2n\hat\theta :

ℓ′′(θ^)=2nθ^2−4nθ^θ^3=−2nθ^2<0 \ell''(\hat\theta) = \frac{2n}{\hat\theta^2} – \frac{4n\hat\theta}{\hat\theta^3} = -\frac{2n}{\hat\theta^2} < 0

It is a maximum. Here the MLE coincides with the moments estimator.

Why substitute instead of studying the sign of ℓ′′ \ell'' in general. The obvious path is to check whether ℓ′′(θ) \ell''(\theta) is always negative. Here it isn’t: ℓ′′(θ)=2nθ3(θ−xˉ) \ell''(\theta) = \frac{2n}{\theta^3}(\theta – \bar x) , negative only for θ<xˉ=14.83 \theta < \bar x = 14.83 . But the curve doesn’t need to be concave everywhere: it’s enough that it is at the only point where the derivative is 0. That’s why ∑xi \sum x_i is replaced with 2nθ^ 2n\hat\theta , and the sign comes out with no numbers.

Part 3. E(θ^)=E(Xˉ)2=2θ2=θ E(\hat\theta) = \frac{E(\bar X)}{2} = \frac{2\theta}{2} = \theta : unbiased. By the variance rule:

Var(θ^)=14 Var(Xˉ)=14⋅2θ2n=θ22n \text{Var}(\hat\theta) = \frac14\,\text{Var}(\bar X) = \frac14\cdot\frac{2\theta^2}{n} = \frac{\theta^2}{2n}

Unbiased and with Var(θ^)→0 \text{Var}(\hat\theta) \to 0 : by the consistency theorem, consistent.

Part 4. log⁡f(x∣θ)=log⁡x−2log⁡θ−x/θ \log f(x\mid\theta) = \log x – 2\log\theta – x/\theta . Differentiating twice:

∂log⁡f∂θ=−2θ+xθ2,∂2log⁡f∂θ2=2θ2−2xθ3 \frac{\partial \log f}{\partial\theta} = -\frac2\theta + \frac{x}{\theta^2}, \qquad \frac{\partial^2 \log f}{\partial\theta^2} = \frac{2}{\theta^2} – \frac{2x}{\theta^3}
i(θ)=−E[2θ2−2Xθ3]=−2θ2+2⋅2θθ3=2θ2,bound=1n⋅2/θ2=θ22n i(\theta) = -E\left[\frac{2}{\theta^2} – \frac{2X}{\theta^3}\right] = -\frac2{\theta^2} + \frac{2\cdot 2\theta}{\theta^3} = \frac{2}{\theta^2}, \qquad \text{bound} = \frac{1}{n\cdot 2/\theta^2} = \frac{\theta^2}{2n}

Unbiased and Var(θ^)=θ22n \text{Var}(\hat\theta) = \frac{\theta^2}{2n} = bound: efficient.

Setting up efficiency. Efficient means “unbiased and with variance equal to the bound”. The first part is already done in part 3; only the bound is missing. For i(θ) i(\theta) you use the second derivative and not the square of the first because 2θ2−2xθ3 \frac{2}{\theta^2} – \frac{2x}{\theta^3} is linear in x: its expectation only needs E(X)=2θ E(X) = 2\theta . With the square you would need E(X2) E(X^2) and more algebra.

Check you’ve got it: why does the Cramér–Rao bound work here but not for the uniform in exercise 2?

Because here X lives on x > 0, and that range doesn’t depend on θ. In the uniform(0, θ) the upper end is θ itself: that’s exactly the mistake in snippet 2 of “What is wrong here?”.

Part 5. The standard error is θ^2/(2n)=θ^/2n \sqrt{\hat\theta^2/(2n)} = \hat\theta/\sqrt{2n} :

n <- length(gap)
theta_ml <- mean(gap) / 2
round(c(theta = theta_ml, std_err = theta_ml / sqrt(2 * n)), 2)

Output:

  theta std_err 
   7.42    1.35 

θ^=7.42 \hat\theta = 7.42 minutes, with a standard error of 1.35. The mean time between two rentals is 2θ^=14.83 2\hat\theta = 14.83 minutes (the sample mean).

How it is marked. Part 1: identifying the gamma or integrating (1), estimator (1). Part 2: log-likelihood and derivative (2), second derivative (1). Part 3: unbiased (0.5), variance (1), consistency by the theorem (0.5). Part 4: information (1), comparing with the variance (1). Part 5: the two numbers (0.5 + 0.5).

Exercise 2

Part 1.

n <- length(canteras)
round(c(moments   = 2 * mean(canteras),
        maximum   = max(canteras),
        corrected = (n + 1) / n * max(canteras)), 2)

Output:

  moments   maximum corrected 
   3308.6    2929.0    3221.9 

Here 2Xˉ=3308.6 2\bar X = 3308.6 is larger than the maximum (2929), so it does not give an impossible fleet, but the three values are almost 400 scooters apart.

Before part 2: what the unknown is. MSE(cM) \text{MSE}(cM) contains both c and θ, but what you choose is c; θ is fixed and you don’t know it. That’s why you differentiate with respect to c. And θ2 \theta^2 factors out: the optimal c doesn’t depend on θ. If it did, you couldn’t use it. The shortcut MSE=Var+b2 \text{MSE} = \text{Var} + b^2 also works, but it needs Var(M) \text{Var}(M) first; expanding the square uses the two expectations from the statement directly.

Part 2. With M=X(n) M = X_{(n)} , expanding the square and using the two expectations given:

MSE(cM)=E[(cM−θ)2]=c2E(M2)−2cθE(M)+θ2=θ2[c2nn+2−2cnn+1+1] \text{MSE}(cM) = E\left[(cM – \theta)^2\right] = c^2E(M^2) – 2c\theta E(M) + \theta^2 = \theta^2\left[c^2\frac{n}{n+2} – 2c\frac{n}{n+1} + 1\right]

It is a parabola in c. Differentiating with respect to c and setting it to 0:

2cnn+2−2nn+1=0⟹c∗=n+2n+1 2c\frac{n}{n+2} – 2\frac{n}{n+1} = 0 \quad\Longrightarrow\quad c^* = \frac{n+2}{n+1}

(the second derivative, 2n/(n+2) 2n/(n+2) , is positive: a minimum). Substituting:

MSE(c∗M)=θ2[(n+2)2(n+1)2⋅nn+2−2 n+2n+1⋅nn+1+1]=θ2[1−n(n+2)(n+1)2]=θ2(n+1)2 \text{MSE}(c^*M) = \theta^2\left[\frac{(n+2)^2}{(n+1)^2}\cdot\frac{n}{n+2} – 2\,\frac{n+2}{n+1}\cdot\frac{n}{n+1} + 1\right] = \theta^2\left[1 – \frac{n(n+2)}{(n+1)^2}\right] = \frac{\theta^2}{(n+1)^2}

because (n+1)2−n(n+2)=1 (n+1)^2 – n(n+2) = 1 .

The MSE of c times the maximum, with n = 10A parabola of the MSE divided by theta squared as a function of c, from 0.9 to 1.25. At c equal to 1, the maximum, it is 0.0152. At c equal to 11/10, the corrected one, 0.00833. The minimum is at c equal to 12/11, with 0.00826, slightly below the corrected one.0.000.020.040.060.91.01.11.2cMSE(c·X₍ₙ₎) / θ²maximum (c = 1)0.01515corrected (11/10)0.00833optimal (12/11)0.00826
The bottom of the parabola is at (n + 2)/(n + 1): slightly below the corrected one.

In the picture, the parabola of the MSE (divided by θ²) with n = 10. The plain maximum (c = 1) is far from the bottom; the corrected one (c = 11/10) almost on it; the minimum is at c = 12/11, a hair to the left of the corrected one.

Part 3. The bias of T=n+2n+1M T = \frac{n+2}{n+1}M :

b(T)=n+2n+1⋅nn+1θ−θ=θ n(n+2)−(n+1)2(n+1)2=−θ(n+1)2 b(T) = \frac{n+2}{n+1}\cdot\frac{n}{n+1}\theta – \theta = \theta\,\frac{n(n+2) – (n+1)^2}{(n+1)^2} = -\frac{\theta}{(n+1)^2}

Biased, downwards, though only slightly (with n = 10, θ/121). Its MSE against the corrected one’s, θ2n(n+2) \frac{\theta^2}{n(n+2)} (theory):

MSE(n+1nM)MSE(T)=θ2/(n(n+2))θ2/(n+1)2=(n+1)2n(n+2)=1+1n(n+2)>1 \frac{\text{MSE}\left(\frac{n+1}{n}M\right)}{\text{MSE}(T)} = \frac{\theta^2/(n(n+2))}{\theta^2/(n+1)^2} = \frac{(n+1)^2}{n(n+2)} = 1 + \frac{1}{n(n+2)} > 1

T is more efficient by the MSE criterion, though only just: with n = 10, 121/120 = 1.008.

Why a ratio and not a difference. Both MSEs carry θ2 \theta^2 , which you don’t know. When you divide, θ disappears and you’re left with a number that only depends on n: if it’s greater than 1, the one in the denominator wins for every θ. With a difference you’d have to discuss the sign of an expression with θ inside.

Check you’ve got it: with θ = 3000 and n = 10, what is the MSE of T, and where does it show up again?

30002/112=9,000,000/121=74,380 3000^2/11^2 = 9{,}000{,}000/121 = 74{,}380 . It’s the number in the mse_theo row, optimal column, of the output in part 5.

Part 4. E(T)=n(n+2)(n+1)2θ→θ E(T) = \frac{n(n+2)}{(n+1)^2}\theta \to \theta (the ratio of degree-2 polynomials tends to 1): asymptotically unbiased. Its variance:

Var(T)=(n+2)2(n+1)2 Var(M)=(n+2)2(n+1)2⋅nθ2(n+1)2(n+2)=n(n+2) θ2(n+1)4→n→∞0 \text{Var}(T) = \frac{(n+2)^2}{(n+1)^2}\,\text{Var}(M) = \frac{(n+2)^2}{(n+1)^2}\cdot\frac{n\theta^2}{(n+1)^2(n+2)} = \frac{n(n+2)\,\theta^2}{(n+1)^4} \xrightarrow[n\to\infty]{} 0

(degree 2 on top, degree 4 below). By the consistency theorem, T is consistent.

Why “unbiased and variance going to 0” isn’t enough. T is biased, so you need the version of the theorem where the expectation tends to θ. There’s a shortcut to double-check: the MSE from part 2, θ2/(n+1)2 \theta^2/(n+1)^2 , already tends to 0, and with the Chebyshev bound from the theory that’s enough.

Part 5.

set.seed(55)
theta <- 3000; n <- 10
sims <- replicate(10000, {
  x <- runif(n, 0, theta)
  c(moments = 2 * mean(x), maximum = max(x), corrected = (n + 1) / n * max(x),
    optimal = (n + 2) / (n + 1) * max(x))
})
mse_sim  <- apply(sims, 1, function(v) mean((v - theta)^2))    # 1: by estimator
mse_theo <- theta^2 * c(1 / (3 * n), 2 / ((n + 1) * (n + 2)), 1 / (n * (n + 2)), 1 / (n + 1)^2)
round(rbind(mse_sim, mse_theo))

Output:

         moments maximum corrected optimal
mse_sim   298165  131962     71547   70831
mse_theo  300000  136364     75000   74380

The formulas are 300,000, 136,364, 75,000 and 74,380, and the simulation is within 5 % of each (the maximum and the last two come out a little short: that is the noise of 10,000 samples, which affects both the same way, because they come from the same maximum). The moments estimator has an MSE four times larger than the others; the corrected and optimal ones almost tie, as the ratio 1.008 said: with 10,000 simulations, that 0.8 % difference does not always show in the order.

Why the same samples and mean((v - theta)^2). Each sample gives the four estimators at once: they’re compared on the same data. And the MSE is the mean of the squared errors, not var(v), which measures the spread around the estimator’s own mean, not around θ. For the maximum, which is biased, var would give about 61,983 instead of 136,364: you’d lose the squared bias (74,380).

Part 6.

round((n + 2) / (n + 1) * max(canteras), 2)

Output:

[1] 3195.27

T estimates a fleet of 3195 scooters. A biased estimator can win because the MSE adds variance and squared bias: T falls a little short on average (bias −θ/121 -\theta/121 ), but multiplying by a number slightly smaller than the corrected one’s also shrinks its variance, and what it gains in variance is more than what it loses to the squared bias.

How it is marked. Part 1: the three numbers (2). Part 2: MSE as a function of c (1), differentiate and solve (1), minimum value (1). Part 3: bias (1), ratio (1), conclusion (1). Part 4: limit of the expectation (1), variance (1), theorem (1). Part 5: simulation (1), comparison (1). Part 6: number (0.5) and explanation (1.5).

Exercise 3

Part 1. With μ = 0, f(x∣v)=12πve−x2/(2v) f(x\mid v) = \frac{1}{\sqrt{2\pi v}}e^{-x^2/(2v)} , and

ℓ(v)=−n2log⁡(2πv)−∑xi22v,ℓ′(v)=−n2v+∑xi22v2=0⟹v^=1n∑Xi2 \ell(v) = -\frac n2\log(2\pi v) – \frac{\sum x_i^2}{2v}, \qquad \ell'(v) = -\frac{n}{2v} + \frac{\sum x_i^2}{2v^2} = 0 \quad\Longrightarrow\quad \hat v = \frac1n\sum X_i^2

ℓ′′(v)=n2v2−∑xi2v3 \ell''(v) = \frac{n}{2v^2} – \frac{\sum x_i^2}{v^3} ; at v^ \hat v , with ∑xi2=nv^ \sum x_i^2 = n\hat v : ℓ′′(v^)=n2v^2−nv^2=−n2v^2<0 \ell''(\hat v) = \frac{n}{2\hat v^2} – \frac{n}{\hat v^2} = -\frac{n}{2\hat v^2} < 0 . A maximum.

Part 2. Each Xi/σ∼N(0,1) X_i/\sigma \sim N(0, 1) , so W=∑Xi2/σ2∼χn2 W = \sum X_i^2/\sigma^2 \sim \chi^2_n , with E(W)=n E(W) = n and Var(W)=2n \text{Var}(W) = 2n . Since v^=σ2nW \hat v = \frac{\sigma^2}{n}W :

E(v^)=σ2n⋅n=σ2,Var(v^)=σ4n2⋅2n=2σ4n E(\hat v) = \frac{\sigma^2}{n}\cdot n = \sigma^2, \qquad \text{Var}(\hat v) = \frac{\sigma^4}{n^2}\cdot 2n = \frac{2\sigma^4}{n}

Unbiased. Note that here the chi-squared has n degrees of freedom, not n − 1: there is no mean to estimate.

Why the chi-squared and not the variance rule. The obvious path is Var(v^)=Var(X2)/n \text{Var}(\hat v) = \text{Var}(X^2)/n , but then you need E(X4)=3σ4 E(X^4) = 3\sigma^4 , which you won’t always remember in the exam. Writing v^ \hat v as a multiple of a chi-squared gives you the expectation and the variance at once, from two facts you do know: n and 2n. Both paths give the same: Var(X2)=3σ4−σ4=2σ4 \text{Var}(X^2) = 3\sigma^4 – \sigma^4 = 2\sigma^4 , and divided by n, 2σ4/n 2\sigma^4/n .

Part 3. log⁡f=−12log⁡(2πv)−x22v \log f = -\frac12\log(2\pi v) – \frac{x^2}{2v} , so

∂log⁡f∂v=−12v+x22v2,∂2log⁡f∂v2=12v2−x2v3 \frac{\partial \log f}{\partial v} = -\frac{1}{2v} + \frac{x^2}{2v^2}, \qquad \frac{\partial^2 \log f}{\partial v^2} = \frac{1}{2v^2} – \frac{x^2}{v^3}
i(v)=−(12v2−E(X2)v3)=−12v2+vv3=12v2,bound=2v2n=2σ4n i(v) = -\left(\frac{1}{2v^2} – \frac{E(X^2)}{v^3}\right) = -\frac{1}{2v^2} + \frac{v}{v^3} = \frac{1}{2v^2}, \qquad \text{bound} = \frac{2v^2}{n} = \frac{2\sigma^4}{n}

Unbiased and with variance equal to the bound: efficient. (With μ = 0, E(X2)=Var(X)=v E(X^2) = \text{Var}(X) = v .)

Part 4. S2 S^2 is unbiased and, in the normal, MSE(S2)=Var(S2)=2σ4n−1 \text{MSE}(S^2) = \text{Var}(S^2) = \frac{2\sigma^4}{n-1} . Ratio:

MSE(S2)MSE(v^)=2σ4/(n−1)2σ4/n=nn−1>1 \frac{\text{MSE}(S^2)}{\text{MSE}(\hat v)} = \frac{2\sigma^4/(n-1)}{2\sigma^4/n} = \frac{n}{n-1} > 1

v^ \hat v is more efficient. It is no coincidence: S2 S^2 measures distances to Xˉ \bar X because it does not know the mean is 0, and pays for that ignorance with a degree of freedom. v^ \hat v uses the information that μ = 0. Besides, since v^ \hat v is efficient, no unbiased estimator can beat it.

Part 5. By invariance, the MLE of σ=v \sigma = \sqrt v is σ^=v^ \hat\sigma = \sqrt{\hat v} :

n <- length(error)
round(c(v_ml = mean(error^2), S2 = var(error), sigma_ml = sqrt(mean(error^2))), 2)

Output:

    v_ml       S2 sigma_ml 
    1.84     1.68     1.36 

v^=1.84 \hat v = 1.84 (km/h)², S2=1.68 S^2 = 1.68 and σ^=1.36 \hat\sigma = 1.36 km/h: the speedometer is typically off by a little over 1 km/h.

Why S2 S^2 comes out smaller than v^ \hat v here. With these data xˉ=−0.55 \bar x = -0.55 , and S2 S^2 measures distances to that −0.55, not to 0. Since ∑(xi−xˉ)2=∑xi2−nxˉ2=22.14−3.64=18.50 \sum (x_i – \bar x)^2 = \sum x_i^2 – n\bar x^2 = 22.14 – 3.64 = 18.50 , dividing by 11 gives 1.68, below 22.14/12=1.84 22.14/12 = 1.84 . Neither is wrong: in this particular sample the mean came out somewhat negative.

Part 6.

set.seed(66)
sim <- replicate(10000, { x <- rnorm(12, 0, 1.5); c(v_ml = mean(x^2), S2 = var(x)) })
round(rbind(mean = apply(sim, 1, mean), variance = apply(sim, 1, var),
            theo_var = c(2 * 1.5^4 / 12, 2 * 1.5^4 / 11)), 3)

Output:

          v_ml    S2
mean     2.241 2.244
variance 0.836 0.928
theo_var 0.844 0.920

Both means are around σ² = 2.25 (both are unbiased) and the variances sit on their formulas, 2⋅1.54/12=0.844 2\cdot 1.5^4/12 = 0.844 and 2⋅1.54/11=0.920 2\cdot 1.5^4/11 = 0.920 .

How it is marked. Part 1: log-likelihood (1), estimator (1), maximum (1). Part 2: chi-squared with n degrees (1), expectation (1), variance (1). Part 3: information (2), conclusion (1). Part 4: MSE of S2 S^2 (1), ratio and conclusion (1). Part 5: the three numbers (1.5), invariance (0.5). Part 6: simulation (1), comparison (1).

Bonus

n <- length(night)
lambda_ml <- 1 / mean(night)
loglik <- function(l) n * log(l) - l * sum(night)
o <- optim(lambda_ml, loglik, method = "Brent", lower = 0.001, upper = 1,
           control = list(fnscale = -1), hessian = TRUE)
data.frame(lambda      = round(lambda_ml, 4),
           var_formula = signif(lambda_ml^2 / n, 3),
           var_optim   = signif(-1 / o$hessian[1, 1], 3),
           std_err     = round(sqrt(lambda_ml^2 / n), 4),
           unbiased    = round((n - 1) / (n * mean(night)), 4))

Output:

  lambda var_formula var_optim std_err unbiased
1 0.0463    8.57e-05  8.57e-05  0.0093   0.0444

1. λ^=1/xˉ=0.0463 \hat\lambda = 1/\bar x = 0.0463 trips ending per minute (a mean duration of 21.6 minutes), with asymptotic variance λ^2/n=8.57⋅10−5 \hat\lambda^2/n = 8.57\cdot 10^{-5} ; optim gives the same from the curvature. 2. The standard error is 0.0093: if we repeated the 25 trips, λ^ \hat\lambda would move around λ with a standard deviation of about 0.009, 20 % of its value. 3. λ∗=n−1nxˉ=0.0444 \lambda^* = \frac{n-1}{n\bar x} = 0.0444 .

Why the unbiased one isn’t 1/xˉ 1/\bar x . The obvious reasoning is “Xˉ \bar X is unbiased for 1/λ 1/\lambda , so 1/Xˉ 1/\bar X is unbiased for λ”. It fails: the expectation doesn’t pass through 1/x 1/x , and in the exponential E(1/Xˉ)=nn−1λ E(1/\bar X) = \frac{n}{n-1}\lambda . That’s why you multiply by n−1n=2425 \frac{n-1}{n} = \frac{24}{25} : 0.0463⋅24/25=0.0444 0.0463\cdot 24/25 = 0.0444 .

Check you’ve got it: if λ were 0.05, around what value would the MLE come out on average with 25 trips?

Around 2524⋅0.05=0.052 \frac{25}{24}\cdot 0.05 = 0.052 : 4 % above λ. With 100,000 simulations in R you get 0.052.

How it is marked. 1: estimate (0.5) and variance both ways (0.5). 2: number (0.5) and interpretation (0.5). 3: number (0.5).

What is wrong here?

Three solutions by other people with one slip each. Before reading the explanation, try to find it.

Snippet 1. A classmate computes in R the MSE of the fleet maximum from exercise 2:

set.seed(1)
m <- replicate(10000, max(runif(10, 0, 3000)))
c(variance = var(m), mse = var(m) + (mean(m) - 3000))

Output:

variance      mse 
59360.93 59093.94 

What is wrong: they get an MSE smaller than the variance, which is impossible. They added the bias without squaring it, and since the maximum’s bias is negative (about −270 scooters), it subtracts. The real MSE is Var+b2=59,361+2672≈130,650 \text{Var} + b^2 = 59{,}361 + 267^2 \approx 130{,}650 (the formula gives 136,364): the squared bias weighs more than the variance.

Adding the bias instead of its square. Quick check: the MSE is never smaller than the variance.

Snippet 2. Another solution, on paper, for the uniform(0, θ):

log f(x|θ) = −log θ   →   ∂/∂θ = −1/θ   →   i(θ) = E[(−1/θ)²] = 1/θ²
Cramér-Rao bound = θ²/n.
Var((n+1)/n · X(n)) = θ²/(n(n+2)) < θ²/n   →   the estimator breaks the bound!
Conclusion: the variance formula for the maximum is wrong.

What is wrong: the variance formula is fine; what does not hold is the bound. The Cramér–Rao inequality requires the support of f not to depend on the parameter, and in the uniform(0, θ) the support is [0,θ] [0, \theta] . With a moving support the bound does not apply, which is why the maximum can have a variance of order 1/n2 1/n^2 .

Before computing a Cramér–Rao bound, look at where X lives. If the end points carry the parameter, there is no bound.

Snippet 3. For exercise 2, someone suggests using only the first scooter seen:

T₁ = 2·X₁.   E(T₁) = 2·θ/2 = θ   →   unbiased.
Since it is unbiased, it is consistent.

What is wrong: unbiased does not imply consistent. Var(T1)=4⋅θ212=θ23 \text{Var}(T_1) = 4\cdot\frac{\theta^2}{12} = \frac{\theta^2}{3} , which does not depend on n: however many scooters you see, T₁ only looks at the first one and its variance does not fall. The consistency theorem asks for both conditions, E→θ E \to \theta and Var→0 \text{Var} \to 0 , and the second one fails.

When you are asked to prove consistency, always write both limits. If one fails, you cannot use the theorem (and almost always the estimator is not consistent).

The three slips in "What is wrong here?"Three panels. 1: three bars, the variance 59,361, the wrongly computed MSE 59,094, lower, and the right one 130,650. 2: two uniform density rectangles with different ends, theta and theta prime: the support changes with the parameter. 3: the variance of 2 times X1, a horizontal line that does not fall with n, against that of 2X̄, which falls towards 0.1. MSE < VarVarwrongright2. Moving supportθθ'the support [0, θ] changes with θ3. Var does not falln2X₁2X̄
An MSE never drops below the variance; no fixed support, no bound; no Var → 0, no consistency.

In the picture, the three slips with their check at a glance: the MSE below the variance, the bound applied with a moving support and the variance that does not fall with n.

Practice quiz

Before moving on to the next topic, check you have got it. This quiz is here to consolidate what this article explains: the ME1 exam is not a multiple-choice test (you solve problems by hand and with R), so no mark here counts. There are 10 questions on the properties of estimators: key ideas, typical mistakes and many «what does this R code print?», with the outputs from really running it. In the short answers, a decimal point or a decimal comma both work. Answer without running anything, press Check and read the explanation for each option; you can repeat it as many times as you like.

Question 1Single choice

A classmate computes the maximum’s MSE as var(m) + (mean(m) - 3000) and gets something smaller than the variance. What did they do wrong?

  1. They added the bias without squaring it; since the bias is negative, it subtracts
  2. They should subtract the bias
  3. They used the mean instead of the median
  4. Nothing: the MSE can be smaller than the variance
Solution

Answer: They added the bias without squaring it; since the bias is negative, it subtracts

Quick check: the MSE is never smaller than the variance.

Question 2Single choice

In the uniform(0, θ), the estimator (n + 1)/n · X(n) has variance θ²/(n(n + 2)), smaller than the «Cramér–Rao bound» θ²/n. What is going on?

  1. The bound does not apply: Cramér–Rao requires the support not to depend on the parameter, and here the support is [0, θ]
  2. The variance formula is wrong
  3. The estimator is biased
  4. Fisher information is computed without the n
Solution

Answer: The bound does not apply: Cramér–Rao requires the support not to depend on the parameter, and here the support is [0, θ]

Before computing a Cramér–Rao bound, look at where X lives. If the endpoints contain the parameter, there is no bound.

Question 3Single choice

T₁ = 2·X₁ (only the first scooter) is unbiased for θ in the uniform(0, θ). Is it consistent?

  1. No: its variance, θ²/3, does not go down as n grows
  2. Yes, because it is unbiased
  3. Yes, because the variance is finite
  4. No, because it is biased
Solution

Answer: No: its variance, θ²/3, does not go down as n grows

When asked to prove consistency, always write both limits.

Question 4Short answer

An estimator has variance 4 and bias −3. What is its MSE?

Solution

Answer: 13

MSE = Var + b² = 4 + (−3)² = 4 + 9 = 13.

Question 5Short answer

What does it print? (It is Var(2X₁) with X₁ ~ uniform(0, 3000), in millions.)

theta <- 3000
4 * theta^2 / 12 / 1e6
Solution

Answer: 3

Var(X₁) = θ²/12 and the constant comes out squared: Var(2X₁) = 4θ²/12 = θ²/3 = 3,000,000, that is, 3 million. It does not depend on n.

Question 6Match

Match each property with its definition:

Bias
Mean squared error
Unbiased
Consistent
Efficient

Definitions:

  • Variance larger than any other's
  • Var(θ̂) + bias²
  • E(θ̂) → θ and Var(θ̂) → 0 as n grows
  • E(θ̂) − θ
  • Unbiased with variance equal to the Cramér–Rao bound
  • Bias 0 for every θ
Solution
  • Bias → E(θ̂) − θ
  • Mean squared error → Var(θ̂) + bias²
  • Unbiased → Bias 0 for every θ
  • Consistent → E(θ̂) → θ and Var(θ̂) → 0 as n grows
  • Efficient → Unbiased with variance equal to the Cramér–Rao bound

To compare: among unbiased ones, smaller variance; in general, smaller MSE. Use the criterion the question asks for.

Question 7True or false

True or false?

  1. A biased estimator can have a smaller MSE than an unbiased one.
  2. The Cramér–Rao bound holds for any distribution.
  3. The Cramér–Rao bound is 1/(n·i(θ)), with i(θ) the information of one observation.
  4. To compare unbiased estimators it is enough to compare their variances.
Solution
  • T — A biased estimator can have a smaller MSE than an unbiased one.
  • F — The Cramér–Rao bound holds for any distribution.
  • T — The Cramér–Rao bound is 1/(n·i(θ)), with i(θ) the information of one observation.
  • T — To compare unbiased estimators it is enough to compare their variances.

That is the case of the fleet’s maximum: biased, but with a small MSE. The bound requires the support not to depend on θ.

Question 8Single choice

In the uniform(0, θ), why is the maximum multiplied by (n + 1)/n?

  1. Because E(X(n)) = n/(n + 1) · θ: the maximum falls short and the factor corrects it so it is unbiased
  2. To reduce its variance
  3. Because that is the method-of-moments estimator
  4. To make it consistent
Solution

Answer: Because E(X(n)) = n/(n + 1) · θ: the maximum falls short and the factor corrects it so it is unbiased

With n = 10 and θ = 3000, E(maximum) = 10/11 · 3000 ≈ 2727: about 270 scooters below.

Question 9Short answer

What does it print? (Expected maximum of 10 uniforms on (0, 3000), rounded.)

round(10 / 11 * 3000)
Solution

Answer: 2727

E(X(n)) = n/(n + 1) · θ = 10/11 · 3000 = 2727.27. The bias is −272.7, the «about −270» of snippet 1.

Question 10Single choice

The Fisher information of one observation is i(θ) = 1/θ² and you have n data. What bound does Cramér–Rao give (if it can be applied)?

  1. θ²/n
  2. θ²
  3. 1/θ²
  4. n/θ²
Solution

Answer: θ²/n

The third question of «Before handing in»: Fisher information is for one observation and the bound has the n.

Try it in the R playground

Paste this script into the R playground: it draws the MSE parabola from part 2 of exercise 2 for any n, and marks the three values of c.

n <- 10
mse_c <- function(c) c^2 * n / (n + 2) - 2 * c * n / (n + 1) + 1     # MSE(c X(n)) / theta^2
curve(mse_c, from = 0.9, to = 1.25, lwd = 2, xlab = "c", ylab = "MSE / theta^2")
abline(v = c(1, (n + 1) / n, (n + 2) / (n + 1)), lty = 2, col = c("grey", "blue", "red"))
round(c(maximum = mse_c(1), corrected = mse_c((n + 1) / n), optimal = mse_c((n + 2) / (n + 1))), 5)

What to look at:

  1. In Plots, the parabola and the three lines: the red one (the optimum) is right at the bottom.
  2. The three numbers in the console: the corrected and the optimal ones are very close.
  3. Change n to 2: the gap between the corrected and the optimal ones is more noticeable.
  4. Change n to 100: the three lines come together near 1.

Cheat sheet: properties of estimators

The essentials in 30 seconds. Bias b=E(θ^)−θ b = E(\hat\theta) – \theta . MSE=Var+b2 \text{MSE} = \text{Var} + b^2 . Unbiased: b=0 b = 0 for every θ. More efficient: smaller variance (between unbiased ones) or smaller MSE (in general). Efficient: variance = bound 1/(n i(θ)) 1/(n\,i(\theta)) , with i(θ)=−E[∂θ2log⁡f(X∣θ)] i(\theta) = -E[\partial^2_\theta \log f(X\mid\theta)] . Consistent if E→θ E \to \theta and Var→0 \text{Var} \to 0 .

I want…Result
bias of S′2 S'^2 −σ2/n -\sigma^2/n
MSE of S2 S^2 and S′2 S'^2 (normal)2σ4n−1 \frac{2\sigma^4}{n-1} and (2n−1)σ4n2 \frac{(2n-1)\sigma^4}{n^2}
maximum of the uniform(0, θ)F(x)=(x/θ)n F(x) = (x/\theta)^n ; E=nn+1θ E = \frac{n}{n+1}\theta ; E(M2)=nn+2θ2 E(M^2) = \frac{n}{n+2}\theta^2 ; Var=nθ2(n+1)2(n+2) \text{Var} = \frac{n\theta^2}{(n+1)^2(n+2)}
MSE of 2Xˉ 2\bar X , X(n) X_{(n)} , n+1nX(n) \frac{n+1}{n}X_{(n)} θ23n \frac{\theta^2}{3n} , 2θ2(n+1)(n+2) \frac{2\theta^2}{(n+1)(n+2)} , θ2n(n+2) \frac{\theta^2}{n(n+2)}
best multiple of the maximumn+2n+1X(n) \frac{n+2}{n+1}X_{(n)} , MSE θ2(n+1)2 \frac{\theta^2}{(n+1)^2}
Fisher informationPoisson 1/λ 1/\lambda ; Bernoulli 1p(1−p) \frac{1}{p(1-p)} ; normal (μ) 1/σ2 1/\sigma^2 ; normal (v = σ², μ known) 12v2 \frac{1}{2v^2} ; exponential 1/λ2 1/\lambda^2
exponentialE(1/Xˉ)=nn−1λ E(1/\bar X) = \frac{n}{n-1}\lambda ; unbiased n−1nXˉ \frac{n-1}{n\bar X} , variance λ2n−2 \frac{\lambda^2}{n-2}
asymptotic variance of the MLE−1/ℓ′′(θ^) -1/\ell''(\hat\theta) ; standard error, its square root
MLE for large nθ^≈N(θ,1/n i(θ)) \hat\theta \approx N\left(\theta, 1/\sqrt{n\,i(\theta)}\right)
In R, I want…Code
to simulate an estimatorreplicate(B, { x <- …; estimator(x) })
to summarise by estimatorapply(sims, 1, f)
the simulated MSEmean((est - theta)^2)
the asymptotic variance with optim-1 / optim(…, control = list(fnscale = -1), hessian = TRUE)$hessian
SymptomLikely cause
MSE smaller than the variancebias not squared
the summary has B numbersapply with margin 2
estimator variance = 0 in the simulationthe sample was generated outside the replicate
an estimator “breaks” the boundsupport that depends on θ, or a biased estimator
NaN in the standard errorthe minus sign of the Hessian is missing

Before handing in, ask yourself:

  1. Have I used the criterion the question asks for (variance or MSE)?
  2. Have I written both limits for consistency?
  3. Is the Fisher information for one observation, and does the bound carry the n?
  4. Do the estimates have 2 decimals and their units?
ME1 exam coming up?The script for every topic, the printable cheat sheet and the pack for each exam, for free.See the pack

For your script

The topic’s functions, tested, for your .R file. No exercise statements: each one says what it does.

## Properties of estimators (ME1, topic 10)

# Simulates one or several estimators: 'generate' returns a sample, 'estimators' a named vector.
simulate_est <- function(generate, estimators, B = 10000) replicate(B, estimators(generate()))

# Summary of a simulation matrix (one estimator per row): mean, bias, variance (over B) and MSE.
summarise_est <- function(sims, theta) {
  mean_est <- apply(sims, 1, mean)
  mse      <- apply(sims, 1, function(v) mean((v - theta)^2))
  round(data.frame(mean = mean_est, bias = mean_est - theta, variance = mse - (mean_est - theta)^2, mse), 4)
}

# Asymptotic variance and standard error of the MLE from the log-likelihood (one parameter).
mle_se <- function(loglik, start, lower, upper) {
  o <- optim(start, loglik, method = "Brent", lower = lower, upper = upper,
             control = list(fnscale = -1), hessian = TRUE)
  c(mle = o$par, asym_var = -1 / o$hessian[1, 1], std_err = sqrt(-1 / o$hessian[1, 1]))
}

# Fisher information of one observation of a discrete variable, as E[(d log f / d theta)^2].
fisher_info_disc <- function(dlogf, dmass, support) sum(dlogf(support)^2 * dmass(support))

# MSE of c * maximum of a uniform(0, theta), divided by theta^2.
mse_c_max <- function(c, n) c^2 * n / (n + 2) - 2 * c * n / (n + 1) + 1

# Usage examples
set.seed(1)
s <- simulate_est(function() runif(12, 0, 2400),
                  function(x) c(mom = 2 * mean(x), cor = 13 / 12 * max(x)), B = 2000)
summarise_est(s, 2400)
mle_se(function(l) 20 * log(l) - l * 238.2, 0.08, 0.001, 1)        # exponential, n = 20, sum 238.2
fisher_info_disc(function(x) -1 + x / 3, function(x) dpois(x, 3), 0:100)   # Poisson(3): 1/3
optimize(mse_c_max, c(0.5, 2), n = 10)$minimum                       # (n + 2) / (n + 1)

What comes next?

With this topic you can now derive an estimator and say whether it is good: whether it is right on average, how wrong it is, whether it reaches the bound and whether it improves with more data. But in every exercise you have given one number (3195 scooters, 7.42 minutes) and, at most, its standard error. The next ME1 topic, confidence intervals, turns that number into a range: “between this and that, with 95 % confidence”. The asymptotic normality of the MLE and its standard error, which you computed in the bonus, are exactly the basis of those intervals.

If you want to go over things first, you have the theory, the proofs and the practice for this topic, and point estimation, where the estimators we have judged here come from.

Keep goingAll Statistics articles

Did this article help you? Here is how you can support SergioLearns →

Ready for the exam?ME1 EC2 mock exam — 4 hours with R beside you, from the normal to confidence intervals, four versions and a mark out of 50 (and why exercise 1 is worth double)