# Question 1 # problematic 100 CI example N <- 100 theta <- 1 xbar.vec <- rnorm(N,theta,sd=1) s.vec <- rchisq(N,df=20) / 20 ci.lngth <- qt(1 - 0.05/2,df=20)*s.vec ind.cov <- xbar.vec - ci.lngth < theta & theta < xbar.vec + ci.lngth plot(1:N,xbar.vec,ylim=c(-3,6),xlab="Experiment",ylab="Theta",pch=3) abline(h=theta,col=4,lwd=2) segments((1:N)[ind.cov],(xbar.vec - ci.lngth)[ind.cov],(1:N)[ind.cov],(xbar.vec + ci.lngth)[ind.cov],col=3) segments((1:N)[!ind.cov],(xbar.vec - ci.lngth)[!ind.cov],(1:N)[!ind.cov],(xbar.vec + ci.lngth)[!ind.cov],col=2) sum(ind.cov) # t.test checking valid coverge property pcov.vec <- rep(NA,1000) for(i in 1:1000) { N <- 100 theta <- 1 xbar.vec <- rnorm(N,theta,sd=1) s.vec <- rchisq(N,df=20) / 20 ci.lngth <- qt(1 - 0.05/2,df=20)*s.vec ind.cov <- xbar.vec - ci.lngth < theta & theta < xbar.vec + ci.lngth pcov.vec[i] <- sum(ind.cov) / N } pcov.vec t.test(pcov.vec)