## Sample sizes. N = c(10,30,50,70,90,110,130) ## Coverage probabilities. CP = NULL ## Loop over the sample sizes. for (k in 1:length(N)) { n = N[k] X = array(rnorm(n*1e4), c(1e4,n)) ## Construct the CI. M = apply(X, 1, mean) C = 1.96/sqrt(n) ## Determine which intervals cover. ci = ((M-C < 0) & (M+C > 0)) ## Calculate the proportion of intervals that cover. CP[k] = mean(ci) }