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 i.i.d. Poisson with mean . From example 11.6 we know that the Cramér–Rao bound for an unbiased estimator for is . The sample mean, , is an unbiased estimator for with (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 / nsdata.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 <- 3v <- 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 ? Can an entry be larger than , 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 <- 3ns <- 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 / nsdata.frame(n = ns, variance = signif(v, 3), bound = signif(bound, 3), efficiency = round(bound / v, 3))The empirical variances in the table follow the bound for all sample sizes, and the estimated efficiencies are clustered around with four of the six entries above this value. This is no contradiction: the theorem only bounds the true variance , whereas the table shows the sample variance of simulated estimates, which is itself random. For a normal sample of size , example 14.6 gives , so that the relative standard error of a sample variance is about , i.e. for . Estimates with a heavier tail than the normal distribution give a larger error. An estimated efficiency of 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 i.i.d. exponential with rate , and an unbiased estimator for which does not attain the bound. From exercise 13.4 we know that the bias-corrected maximum likelihood estimator is unbiased and has variance . On the other hand, the bound from example 11.8 is and thus the efficiency of this estimator is . By the same exercise, is the UMVUE, and thus no unbiased estimator for the rate has efficiency larger than .
We repeat the analysis of the previous section for with . 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 for , , , and . Considering the simulation error we have observed, for which sample sizes could the simulation be expected to distinguish from an efficient estimator?
For , and the simulated efficiencies are close to the exact values and clearly below . The estimator has a heavy right tail, and repeating the simulation with other seeds shows that the estimated efficiency fluctuates by about for and by about for and . For these two sample sizes, the exact loss of and is comparable to this error: the simulated suggests a larger loss than the true one, and the simulated suggests no loss at all. We would need considerably more than repetitions to resolve these values. The loss of efficiency, , goes to zero as increases: 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 and the score . Dividing both sides of this inequality by shows that the efficiency of is given by the squared correlation between and the score. This equals , if and only if is a multiple of the score. For the Poisson sample equals times the score, and thus the correlation is without any calculation. For the exponential sample 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 . 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.
The squared correlation coincides with the efficiency 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 with from proposition 13.5. Before you look at the plot, predict where the points will lie for an efficient estimator.

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 , computed using var, as an estimator for for a normal sample with and . The bound for this estimator is given in example 14.6, together with the variance of . Repeat the study of section 15.1 for , and create a table which shows the estimated and the exact efficiencies for the sample sizes in ns. Finally, in three sentences, discuss whether is efficient, how large its loss of efficiency is, and, using the relative error from section 15.1, how many repetitions would be required to see the loss of efficiency of at .
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.
-
•
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 for repetitions, i.e. for , and more for estimators with heavy tails. It can be greater than . A simulation can only detect a loss of efficiency larger than this error.
-
•
The Poisson mean is efficient for all . The bias-corrected exponential-rate estimator has efficiency . The efficiency is the square of the correlation between the estimator and the score, and equals , if and only if the estimator is a linear function of the score.