Lecture 15 Cramér–Rao and Efficiency in R

In lecture 13 we proved the Cramér–Rao inequality, theorem 13.2. In this lecture we compare two unbiased estimators with the bound by simulation. The sample mean of a Poisson sample attains the bound. The bias-corrected maximum likelihood estimator for the exponential rate does not, and we use proposition 13.5 to see why. As in the previous R sessions, appendix B covers the R commands we use, and we predict the outcome of each simulation before we run it.

15.1 An Efficient Estimator Against the Bound

In this section we consider X1,…,XnX_{1},\dots,X_{n} i.i.d. Poisson with mean θ=3\theta=3. From example 11.6 we know that the Cramér–Rao bound for an unbiased estimator for θ\theta is θ/n\theta/n. The sample mean, X¯\bar{X}, is an unbiased estimator for θ\theta with Varθ(X¯)=θ/n\mathop{\mathrm{Var}}\nolimits_{\theta}(\bar{X})=\theta/n (see lemma 2.2) and thus, by definition 13.4, is an efficient estimator. We check this by simulation, with the loop over ns from lecture 9. The command var can be used to compute the sample variance of a vector of estimates, and dividing the bound by this value allows us to estimate the efficiency of the estimator. The full script for this section, with lines intentionally shuffled (except for the function body and the loop which are left as one piece), is given in the following box. Before you can run the script, you will need to arrange the lines yourself.

bound <- theta / ns
data.frame(n = ns, variance = signif(v, 3), bound = signif(bound, 3),
efficiency = round(bound / v, 3))
est_pois <- function(n, theta) {
mean(rpois(n, lambda = theta))
}
set.seed(2026)
for (j in seq_along(ns)) {
v[j] <- var(replicate(10000, est_pois(ns[j], theta)))
}
theta <- 3
v <- numeric(length(ns))
ns <- c(5, 10, 20, 50, 100, 200)

As in lectures 6 and 9, all names must be defined before they are used: the function, theta and ns come first, v needs length(ns), the seed must be set before the loop, and the table must be created last. Before you try the reconstructed script, make a prediction for the efficiency column. Will all entries be exactly 11? Can an entry be larger than 11, despite the fact that theorem 13.2 states that no unbiased estimator can have a variance smaller than the bound?

est_pois <- function(n, theta) {
mean(rpois(n, lambda = theta))
}
theta <- 3
ns <- c(5, 10, 20, 50, 100, 200)
v <- numeric(length(ns))
set.seed(2026)
for (j in seq_along(ns)) {
v[j] <- var(replicate(10000, est_pois(ns[j], theta)))
}
bound <- theta / ns
data.frame(n = ns, variance = signif(v, 3), bound = signif(bound, 3),
efficiency = round(bound / v, 3))
## n variance bound efficiency
## 1 5 0.5970 0.600 1.005
## 2 10 0.3000 0.300 1.001
## 3 20 0.1510 0.150 0.995
## 4 50 0.0590 0.060 1.017
## 5 100 0.0297 0.030 1.010
## 6 200 0.0150 0.015 0.999

The empirical variances in the table follow the bound for all sample sizes, and the estimated efficiencies are clustered around 11 with four of the six entries above this value. This is no contradiction: the theorem only bounds the true variance Varθ(X¯)\mathop{\mathrm{Var}}\nolimits_{\theta}(\bar{X}), whereas the table shows the sample variance of N=10000N=10000 simulated estimates, which is itself random. For a normal sample of size NN, example 14.6 gives Var(S2)=2⁢σ4/(N−1)\mathop{\mathrm{Var}}\nolimits(S^{2})=2\sigma^{4}/(N-1), so that the relative standard error of a sample variance is about 2/N\sqrt{2/N}, i.e. 1.4%1.4\% for N=10000N=10000. Estimates with a heavier tail than the normal distribution give a larger error. An estimated efficiency of 1.0171.017 thus means that, within the limits of error of the simulation, the estimator is efficient.

15.2 An Estimator Not Attaining the Bound

In this section we consider X1,…,XnX_{1},\dots,X_{n} i.i.d. exponential with rate θ>0\theta>0, and an unbiased estimator for θ\theta which does not attain the bound. From exercise 13.4 we know that the bias-corrected maximum likelihood estimator θ~=(n−1)/∑iXi\tilde{\theta}=(n-1)/\sum_{i}X_{i} is unbiased and has variance θ2/(n−2)\theta^{2}/(n-2). On the other hand, the bound from example 11.8 is θ2/n\theta^{2}/n and thus the efficiency of this estimator is (n−2)/n(n-2)/n. By the same exercise, θ~\tilde{\theta} is the UMVUE, and thus no unbiased estimator for the rate has efficiency larger than (n−2)/n(n-2)/n.

We repeat the analysis of the previous section for θ~\tilde{\theta} with θ=2\theta=2. To do this, we replace est_pois by the function est_exp below, both in its definition and in the loop. We then set theta <- 2 and ns <- c(5, 10, 20, 50, 100), re-create v, reset the seed as before and replace the bound by theta^2 / ns. The resulting script is R/S15-efficiency.R. Before you run the script, write down (n−2)/n(n-2)/n for n=5n=5, 1010, 2020, 5050 and 100100. Considering the simulation error we have observed, for which sample sizes could the simulation be expected to distinguish θ~\tilde{\theta} from an efficient estimator?

est_exp <- function(n, theta) {
(n - 1) / sum(rexp(n, rate = theta))
}
data.frame(n = ns, efficiency = round(bound / v, 3), exact = (ns - 2) / ns)
## n efficiency exact
## 1 5 0.607 0.60
## 2 10 0.803 0.80
## 3 20 0.903 0.90
## 4 50 0.929 0.96
## 5 100 1.008 0.98

For n=5n=5, 1010 and 2020 the simulated efficiencies are close to the exact values and clearly below 11. The estimator θ~\tilde{\theta} has a heavy right tail, and repeating the simulation with other seeds shows that the estimated efficiency fluctuates by about 0.030.03 for n=5n=5 and by about 0.0150.015 for n=50n=50 and 100100. For these two sample sizes, the exact loss of 4%4\% and 2%2\% is comparable to this error: the simulated 0.9290.929 suggests a larger loss than the true one, and the simulated 1.0081.008 suggests no loss at all. We would need considerably more than 1000010000 repetitions to resolve these values. The loss of efficiency, 2/n2/n, goes to zero as nn increases: θ~\tilde{\theta} is asymptotically efficient in the sense of lecture 17, but not efficient.

To explain the difference between the two estimators, we return to the proof of theorem 13.2 in lecture 13, which uses the Cauchy–Schwarz inequality between the estimator TT and the score ℓ′⁢(θ)\ell^{\prime}(\theta). Dividing both sides of this inequality by Varθ(T)⁢ℐ︀n⁢(θ)\mathop{\mathrm{Var}}\nolimits_{\theta}(T)\,\mathcal{I}_{n}(\theta) shows that the efficiency of TT is given by the squared correlation between TT and the score. This equals 11, if and only if T−θT-\theta is a multiple of the score. For the Poisson sample X¯−θ\bar{X}-\theta equals θ/n\theta/n times the score, and thus the correlation is 11 without any calculation. For the exponential sample θ~−θ\tilde{\theta}-\theta is a function of the score, but not a linear one. The following function computes the estimation error and the score for a given sample of size n=5n=5. The command cor can be used to compute the correlation of two vectors. Predict the value of the squared correlation before you run the code.

n <- 5
err_score <- function(n, theta) {
x <- rexp(n, rate = theta)
c((n - 1) / sum(x) - theta, n / theta - sum(x))
}
set.seed(2026)
expo <- replicate(2000, err_score(n, 2))
cor(expo[1, ], expo[2, ])^2
## [1] 0.6147813

The squared correlation 0.6150.615 coincides with the efficiency 3/53/5 from the table, up to simulation error. To see where the remaining variance comes from, we plot the estimation error against the score and add the line c⁢(θ)⁢ℓ′⁢(θ)c(\theta)\,\ell^{\prime}(\theta) with c⁢(θ)=θ2/nc(\theta)=\theta^{2}/n from proposition 13.5. Before you look at the plot, predict where the points will lie for an efficient estimator.

plot(expo[2, ], expo[1, ], pch = 20, xlab = "score",
ylab = "estimation error")
abline(a = 0, b = theta^2 / n, lty = 2)
Scatter plot of 2000 points, estimation error
against score, for exponential samples of size 5. The points lie
on a smooth increasing curve, which is flat near -1.3 for
negative scores and rises steeply to about 10 as the score
approaches 2. A dashed straight line through the origin with
slope 0.8 crosses the curve twice and lies away from it
elsewhere.
Figure 15.1: Estimation error θ~−θ\tilde{\theta}-\theta against the score ℓ′⁢(θ)\ell^{\prime}(\theta) for 20002000 exponential samples of size n=5n=5 with θ=2\theta=2. The dashed line is c⁢(θ)⁢ℓ′⁢(θ)c(\theta)\,\ell^{\prime}(\theta) with c⁢(θ)=θ2/nc(\theta)=\theta^{2}/n.

By proposition 13.5, every point lies on the dashed line for an efficient estimator. In figure 15.1 the points lie on a curve instead. The vertical distances between the points and the line are the part of the error which the score does not explain, and this part is the reason for the loss of efficiency.

15.3 A Task to Take Home

The following task is in a style similar to the practical report. Consider the sample variance S2S^{2}, computed using var, as an estimator for σ2\sigma^{2} for a normal sample with μ=0\mu=0 and σ2=1\sigma^{2}=1. The bound 2⁢σ4/n2\sigma^{4}/n for this estimator is given in example 14.6, together with the variance 2⁢σ4/(n−1)2\sigma^{4}/(n-1) of S2S^{2}. Repeat the study of section 15.1 for S2S^{2}, and create a table which shows the estimated and the exact efficiencies for the sample sizes in ns. Finally, in three sentences, discuss whether S2S^{2} is efficient, how large its loss of efficiency is, and, using the relative error 2/N\sqrt{2/N} from section 15.1, how many repetitions NN would be required to see the loss of efficiency of S2S^{2} at n=100n=100.

Before the next session, you should type the commands used in this session, and should check that you get the same results as the text.

Summary.
  • •
    ​

    The estimated efficiency, i.e. the ratio of the Cramér–Rao bound to the sample variance of the simulated estimates, fluctuates around the true efficiency by about 2/N\sqrt{2/N} for NN repetitions, i.e. 1.4%1.4\% for N=10000N=10000, and more for estimators with heavy tails. It can be greater than 11. A simulation can only detect a loss of efficiency larger than this error.

  • •
    ​

    The Poisson mean is efficient for all nn. The bias-corrected exponential-rate estimator has efficiency (n−2)/n(n-2)/n. The efficiency is the square of the correlation between the estimator and the score, and equals 11, if and only if the estimator is a linear function of the score.