set.seed(12343) CIlower<-numeric(10000) CIupper<-numeric(10000) pvalue1<-numeric(10000) for(j in 1:10000) { sample<-rnorm(100,10,2) testres1<-t.test(sample,mu=10) CIlower[j]<-testres1$conf.int[1] CIupper[j]<-testres1$conf.int[2] pvalue1[j]<-testres1$p.value } testres1$conf.int[1] testres1$conf.int[2] testres1$p.value reject1<-pvalue1<=0.05 table(reject1) color<-rep(gray(.7),100) color[reject1]<-"black" plot(0, xlim=c(9,11), ylim=c(1,100), ylab="Sample No.", xlab="", main="95% Confidence Interval") abline(v=10, lty=2) for(j in 1:100) { lines(c(CIlower[j], CIupper[j]), c(j,j), col=color[j], lwd=1) }