## simulate a bunch of confidence intervals to illustrate coverage ## ADM 10/7/2007 set.seed(1234) ## toss N coins and count the number of heads N <- 50 ## repeat simulation G times G <- 100 ## vector of draws draws <- rbinom(G,N,0.5)/N ## look at the draws hist(draws, freq=FALSE) ## compute 95% confidence intervals SE <- sqrt(draws * (1-draws)/N) ## plot the correct 95% confidence intervals matplot(rbind(draws - 1.96 * SE, draws+1.96*SE), rbind(1:G, 1:G), type="l", lty=1, xlab="Proportion", ylab="Draw") abline(v=.5) ## plot incorrect 95% confidence intervals (just one SE) matplot(rbind(draws - 1 * SE, draws+1*SE), rbind(1:G, 1:G), type="l", lty=1, xlab="Proportion", ylab="Draw") abline(v=.5)