cliff_pilot_power_analysis2.R 584 B

1234567891011121314151617181920212223242526272829303132
  1. library(pwr)
  2. # First Question: What was the Power of Our Study, With Different Effect Sizes
  3. p <<- .05
  4. N <- 30
  5. w <- seq(from = .07, to = .5, length=50)
  6. df <- 1
  7. results <- data.frame()
  8. ct <- function(w) {
  9. result <- pwr.chisq.test(w=w, df=df, sig.level=p, N=N)
  10. return(result$power)
  11. }
  12. power <- sapply(w, ct)
  13. results <- data.frame(p, N, w, df, power)
  14. library(ggplot2)
  15. ggplot(results, aes(x=w, y=power)) +
  16. geom_line() +
  17. ggtitle(sprintf('Power of Chi-Square Test of Decision Pilot Cliff Avoidance Experiment,\nfor different Effect Sizes (N=%i, p=%.2f)', N, p))