Lecture 27 Coverage and Level by Simulation
This is the R session for week 9 of the course. In lectures this week we have seen Wilks’ theorem and confidence intervals. Both come with a stated probability: a confidence interval covers the true parameter value with probability , and the likelihood-ratio test with a critical value from the chi-squared distribution has size close to for large . In this session we check both statements by simulation. The written reference for the R commands is in appendix B.
27.1 Coverage by Simulation
We first use the -interval from example 26.3, with the numerical values and (known) from that example, so that the interval is . Since in that example is a pivot, the random interval contains the fixed value with probability exactly , whatever the value of . To see what this means, we take and compute the interval for samples. Before you execute the code, answer the following questions: (1) How many of the intervals will not cover the value ? (2) Will the misses come in runs, or be scattered at random among the samples?
As in lecture 12, covers is a vector of TRUE and FALSE, one for each interval, and the command sum can be used to count the TRUE values. In our example, out of intervals cover the truth, and the misses are for samples , , , and . The exact number is a coincidence of the seed: the number of intervals which cover the truth is binomially distributed with standard deviation , so or would have been just as unremarkable.
Figure 27.1 shows each interval as a horizontal line, with the intervals which cover the truth in grey and the misses in black. The script R/S27-coverage.R shows how the command segments can be used to create this plot.

The intervals in the figure all have the same width, since is known: the intervals move, while the dashed line stays fixed. The misses are scattered at random through the figure, since the samples are independent.
Sample gives the interval . Before reading on, decide whether the following statement is correct: “ is in the interval with probability ”.
The statement is wrong, since the parameter is a fixed number: the interval computed from sample either contains or it does not, and here it does not. Nothing in sample shows this, since its interval looks like any other. The probability refers to the procedure, not to the computed interval. In the script R/S27-coverage.R, intervals give the coverage , which is within simulation error of .
27.2 Wilks’ Theorem in Action
We now turn from an exact statement to an approximate one. Assume that the variance of the normal sample is not known, so that the model has the two parameters and , and consider the likelihood-ratio test of , where leaves free. By exercise 25.1, the likelihood-ratio statistic is
Since fixes and leaves the nuisance parameter free, we have , and by Wilks’ theorem (theorem 25.3) the distribution of under converges to as . Under we can write with i.i.d. standard normal , and the factor cancels in the ratio. Thus the distribution of under is the same for every , and the rejection rate for one value of is the size of the test. We simulate under for and , using and the value from the first section, and we reject if is at least the critical value of , as if the theorem were exact. Before you run the code, predict the rejection rate for : will it be above or below , and by roughly how much?
theta0 <- 10wilks <- function(n) { x <- rnorm(n, mean = theta0, sd = sigma) n * log(sum((x - theta0)^2) / sum((x - mean(x))^2))}set.seed(2026)w10 <- replicate(10000, wilks(10))w100 <- replicate(10000, wilks(100))crit_w <- qchisq(0.95, df = 1)c(n10 = mean(w10 >= crit_w), n100 = mean(w100 >= crit_w))The rejection rate for is , which is within simulation error of the nominal level. The rejection rate for is , with a simulation standard error of about , and exercise 25.1 leads to the exact size : the test with nominal level has type I errors about more often than it should. Figure 27.2 shows the same effect in the distribution of . In its quantile plots, made in the same way as the normal quantile plots of lecture 12, the points for lie above the line throughout, with a gap which grows in the upper tail. Thus large values of are more likely than the limit predicts.

The error carries over to intervals: by the proof of lemma 26.6, the confidence interval obtained by inverting the test with critical value covers the truth with probability one minus the size of the test, which is about for samples of size , whatever the values of and . For this model an exact test exists, and lecture 31 builds it. In general, the size given by Wilks’ theorem is reached only in the limit. An exact test should be used if one is available, and if not, a simulation under can be used to determine the actual size at a given .
27.3 A Task to Take Home
Repeat the picture in figure 27.1 for the -interval from example 26.4, with . In the last line of z_interval, replace sigma by sd(x) and qnorm(0.975) by qt(0.975, df = 4), and note that the intervals now differ in width. Estimate the long-run coverage from samples. Then repeat the experiment with qnorm(0.975) in place of the quantile, and comment on your result.
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 commands used in this session is appendix B.
-
•
The confidence level is a property of the procedure: in repeated samples, about of the intervals contain the truth, and the misses look like the other intervals. A computed confidence interval either contains the parameter or it does not.
-
•
For the normal mean with unknown variance, the likelihood-ratio statistic is only approximately chi-squared: for the chi-squared critical value gives size about instead of , and the inverted interval has coverage about . For the approximation is good.
-
•
If an exact test or interval is available, this should be used. If not, simulation can be used to determine the actual size or coverage at the given .