Lecture 15 Cramer–Rao and Efficiency in R
This is the R session for week 5. Last week in lectures we proved the Cramer–Rao inequality (theorem 13.2). This week we will try to translate this bound into numbers: we will consider an efficient estimator with variance on the bound, an inefficient estimator and the reason for its inefficiency, and the uniform model where the bound is beaten because the theorem does not apply. As usual, appendix B has a written version of the material we will discuss, and we will try to predict the outcome of each simulation before we perform the simulation.
15.1 An Efficient Estimator Against the Bound
Our model of choice for this section is i.i.d. Poisson with mean . From example 11.6 we know that the Cramer–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 use simulation to verify this claim, using 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 half of the entries above this value. The following argument shows that this is no contradiction: the statement of the theorem only bounds the true variance , whereas the table shows the variance of random estimates. The random sample is off the true value by one or two percent in either direction, as shown in lecture 6. An estimated efficiency of means that, within the limits of error of the simulation, the estimator is efficient.
15.2 Attaining and Missing the Bound
In this section we show that not every unbiased estimator is efficient. As an example, from exercise 13.4 we know that the bias-corrected maximum likelihood estimator for the exponential rate is unbiased and has variance . On the other hand, the bound from example 11.8 is and thus the efficiency of this estimator is . We can perform a similar analysis as in the previous section, this time for with : To do this we write a new function (below est_pois in the code) to compute the estimator, keep the loop as before, adjust the range of ns to to , and replace the bound by theta^2 / ns. The resulting script is R/S15-efficiency.R. Before you can run the script, you need to 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 simulation coincides with the exact efficiencies up to two decimal digits. For and the difference to is and , comparable to the size of the simulation error. Thus, the last two rows do not give useful results and we would need significantly more than repetitions to resolve these results. The loss of efficiency is a constant factor which goes to zero as increases: is asymptotically efficient in the sense of lecture 17, but not efficient.
Where does the difference come from? The proof of theorem 13.2 in lecture 13 uses the Cauchy–Schwarz inequality between the estimator and the score . Dividing through 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. A plot of expo[1, ] against expo[2, ] shows that the points lie on a curve instead of on a straight line. The curvature of this curve is evidence that the bound does not account for all of the variance.
15.3 Beating the Bound Without Breaking It
Example 13.6 is this week’s counterexample: for i.i.d. uniformly distributed on the set , the estimator is unbiased and has variance , whereas the Cramer–Rao formula, using the value from example 11.11, would give . The following function computes, for the same sample, the bias-corrected maximum and the method of moments estimator , both of which are unbiased. Thus, the variances are what the theorem would be about, if it held. The command apply can be used to apply a function to every row (second argument 1) or column (2) of a matrix, in this case to compute the variance var for each row of estimates. Before you try the code, make a prediction: which of the two columns will be below the column ? Will the other column be above it?
est_both <- function(n, theta) { x <- runif(n, min = 0, max = theta) c((n + 1) * max(x) / n, 2 * mean(x))}theta <- 1ns <- c(5, 10, 20, 50, 100, 200, 500, 1000)vars <- matrix(0, nrow = length(ns), ncol = 2)set.seed(2026)for (j in seq_along(ns)) { ests <- replicate(10000, est_both(ns[j], theta)) vars[j, ] <- apply(ests, 1, var)}rownames(vars) <- nscolnames(vars) <- c("(n + 1) max / n", "2 * mean")signif(cbind(vars, "theta^2 / n" = theta^2 / ns), 3)The variance of is by exercise 2.2, one third of the formal bound at every . The first column is below the formal bound throughout and falls away from it: at the variance of the corrected maximum is , one thousandth of . As in lecture 9, a plot on log-log axes shows the rates. Predict the slopes of the two sets of points and of the dashed line .

In figure 15.1 the open circles are parallel to the dashed line with slope , corresponding to the usual rate, and the filled circles follow the dotted line with slope : figure 9.2 again, with the value added and filled circles placed below it from the first sample size on. Nothing is broken. The regularity conditions of theorem 13.2 are violated by the uniform distribution, since the support of the distribution moves with : example 11.11 shows that the score does not have mean zero and that the differentiation under the integral sign used in the proof is not possible. Thus, the value cannot be a bound and indeed it is a formula used outside its domain of validity, and an estimator with variance smaller than this value is called super-efficient. The same failure of regularity is shown in exercise 17.3 to cause the rate of the maximum.
15.4 A Task to Take Home
The following task allows you to practice the methods we have learned in this lecture, in a style similar to the practical report. First, you should repeat the study of section 15.1 for the Bernoulli distribution with , where is unbiased and the bound is as shown in example 11.5. Create a table which shows the estimated efficiencies for the sample sizes in ns. Next, 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. Compute the exact variance of using the chi-squared distribution of from proposition A.3. Compare the exact efficiency of your estimator to the values in the table. Finally, in three sentences, discuss which of the two estimators is efficient, how much less efficient the other one is, and how many repetitions of your simulation would be required to see the less efficient estimator 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 written reference for the functions var and apply is appendix B.
-
•
The estimated efficiency, i.e. the ratio of the Cramer–Rao bound to the sample variance of the simulated estimates, fluctuates around the true efficiency by one or two percent for repetitions and can be greater than . A simulation is only able to detect an efficiency loss, if the loss is bigger 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.
-
•
For the uniform parameter, the variance of decreases as , and is smaller than the value from the Cramer–Rao formula, since the regularity conditions are violated. The formula is not a bound in this case.