set.seed(1) N<-100000 height.male<-rnorm(N,69.5,2.75) # 5 foot, 9.5 inches height.female<-rnorm(N, 64.5, 2.75) # 5 foot, 4.5 inches par(mfrow=c(2,1)) hist(height.male, freq=FALSE, xlim=c(55,80)) hist(height.female, freq=FALSE, xlim=c(55,80)) n<-5 height.male.sample<-rnorm(n,69.5,2.75) height.female.sample<-rnorm(n,64.5,2.75) t.test(height.male.sample,height.female.sample) pval<-NULL for (i in 1:1000) { height.male.sample<-rnorm(n,69.5,2.75) height.female.sample<-rnorm(n,64.5,2.75) pval[i]<-t.test(height.male.sample,height.female.sample)$p.value } sum(pval<.05)/1000 N<-100000 height.male.white<-rnorm(N,70.5,2.75) # 5 foot, 10.5 inches height.male.latino<-rnorm(N, 67, 2.75) # 5 foot, 7 inches par(mfrow=c(2,1)) hist(height.male.white, freq=FALSE, xlim=c(55,80)) hist(height.male.latino, freq=FALSE, xlim=c(55,80)) n<-20 height.male.white.sample<-rnorm(n,70.5,2.75) height.male.latino.sample<-rnorm(n,67,2.75) t.test(height.male.white.sample,height.male.latino.sample) pval<-NULL for (i in 1:1000) { height.male.white.sample<-rnorm(n,70.5,2.75) height.male.latino.sample<-rnorm(n,67.5,2.75) pval[i]<-t.test(height.male.white.sample,height.male.latino.sample)$p.value } sum(pval<.05)/1000 prob.dis.treat<- 0.2 prob.dis.control<-0.3 n<-20 pval<-NULL for (i in 1:1000) { dis.treat<-rbinom(1,n,prob.dis.treat) dis.control<-rbinom(1,n,prob.dis.control) pval[i]<-chisq.test(matrix(c(dis.treat,n-dis.treat,dis.control,n-dis.control),nrow=2))$p.value } sum(pval<.05)/1000