set.seed(123456) par(mfrow=c(1,3)) CIlower<-numeric(10000) CIupper<-numeric(10000) pvalue1<-numeric(10000) pvalue2<-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 pvalue2[j]<-t.test(sample, mu=9.5)$p.value } reject1<-pvalue1<=0.05 table(reject1) reject2<-pvalue2<=0.05 table(reject2) par(mfrow=c(2,2)) color<-rep(gray(.7),100) color[reject1[1:100]]<-"black" plot(0, xlim=c(9,11), ylim=c(1,100), ylab="Sample No.", xlab="", main="Corrrect H0") abline(v=10, lty=2) for(j in 1:100) { lines(c(CIlower[j], CIupper[j]), c(j,j), col=color[j], lwd=1) } color<-rep(gray(.7),100) color[reject2[1:100]]<-"blue" plot(0, xlim=c(9,11), ylim=c(1,100), ylab="Sample No.", xlab="", main="Incorrrect H0") abline(v=9.5, lty=2) for(j in 1:100) { lines(c(CIlower[j], CIupper[j]), c(j,j), col=color[j], lwd=1) } set.seed(123456) CIlower<-numeric(10000) CIupper<-numeric(10000) pvalue1<-numeric(10000) pvalue2<-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 pvalue2[j]<-t.test(sample, mu=9.3)$p.value } reject1<-pvalue1<=0.05 table(reject1) reject2<-pvalue2<=0.05 table(reject2) color<-rep(gray(.7),100) color[reject2[1:100]]<-"black" plot(0, xlim=c(9,11), ylim=c(1,100), ylab="Sample No.", xlab="", main="Incorrrect H0") abline(v=9.3, lty=2) for(j in 1:100) { lines(c(CIlower[j], CIupper[j]), c(j,j), col=color[j], lwd=1) } set.seed(123456) CIlower<-numeric(10000) CIupper<-numeric(10000) pvalue1<-numeric(10000) pvalue2<-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 pvalue2[j]<-t.test(sample, mu=9.2)$p.value } reject1<-pvalue1<=0.05 reject2<-pvalue2<=0.05 table(reject1) table(reject2) color<-rep(gray(.7),100) color[reject2[1:100]]<-"dark red" plot(0, xlim=c(9,11), ylim=c(1,100), ylab="Sample No.", xlab="", main="Incorrrect H0") abline(v=9.2, lty=2) for(j in 1:100) { lines(c(CIlower[j], CIupper[j]), c(j,j), col=color[j], lwd=1) }