15  Power analysis

The current course only provides a basic introduction to power analysis. Package pwr offers power analysis for, among others, t tests, proportion tests and chi squared tests. The usage of package pwr is not exam material.

Calculate power for a two sample t-test with a given sample size (n = 30) and effect size (Cohen’s d = 0.5):

library(pwr)
Warning: package 'pwr' was built under R version 4.4.3
pwr.t.test(n = 30, d = 0.5, sig.level = .05, type = "two.sample",
           alternative = "two.sided")

     Two-sample t test power calculation 

              n = 30
              d = 0.5
      sig.level = 0.05
          power = 0.4778965
    alternative = two.sided

NOTE: n is number in *each* group

If we want to know what sample size is required for detecting an effect size of d = 0.8 with 80% power, we omit n from the arguments:

pwr.t.test(d = 0.3, power = 0.8, sig.level = .05, type = "two.sample",
           alternative = "two.sided")

     Two-sample t test power calculation 

              n = 175.3847
              d = 0.3
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: n is number in *each* group