# R. Chris Fraley | Nov 29 2002 # Estimate statistical power of a correlation # To use this program, simply plug in the expected or hypothesized mean for each group (m1 and m2) # as well as the hypothesized standard deviation (k) and sample size (n). # At the end, the program will tell you the proportion of times that you'll obtain # a p-value less than 5%. m1<- 10 # hypothesized mean for group 1 m2<- 11 # hypothesized mean for group 2 k<-1 # hypothesized sd within each condition n<-10 # number of people #----------------------------------------------------------- # The rest of this doesn't need to be adjusted by the user. #----------------------------------------------------------- trials<-1000 p.vec<-rep(99999,trials) for(i in 1:trials){ x1<-rnorm(n,mean=m1,sd=k) # simulate data for cell 1 x2<-rnorm(n,mean=m2,sd=k) # simulate data for cell 2 p.vec[i]<-t.test(x1,x2)$p.value } cat("Proportion of times the null hypothesis will be rejected ","\n") print(table(p.vec<=.05)/trials)