## Sample sizes N = c(10,30,50,70,90,110,130) ## Coverage probabilities for each sample size. CP = array(0, length(N)) for (k in 1:length(N)) { n = N[k] X = array(rexp(n*1000), c(1000,n)) ## Construct the CI. M = apply(X, 1, mean) MX = apply(X, 1, max) MN = apply(X, 1, min) C = (MX - MN)/(2*sqrt(n)) ## Determine which intervals cover EX=1. ci = ((M-C < 1) & (M+C > 1)) ## Calculate the proportion of intervals that cover. CP[k] = mean(ci) }