# R. Chris Fraley | Nov 29 2002 # Estimate statistical power of a correlation # To use this program, simply plug in the expected or hypothesized correlation # and the corresponding sample size. # At the end, the program will tell you the proportion of times that you'll obtain # a p-value less than 5%. n<-160 r<-.22 #----------------------------------------------------------- # 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) x2<-r*x1 + rnorm(n,0,sqrt(1-r^2)) p.vec[i]<-cor.test(x1,x2)$p.value } cat("Proportion of times the null hypothesis will be rejected ","\n") print(table(p.vec<=.05)/trials)