Sample size determination in R

Given group means 50, 60, 50, and 60; experimental error variance 52 = 25; a level-0.05 test with power 0.90 at these settings; find common sample size.

> mu <- c(A=50, B=60, C=50, D=60) # given group means

> var(mu)

[1] 33.33333

> power.anova.test(groups = 4,   # or use groups=length(mu)

+     between.var = var(mu),

+     within.var = 5^2,  # given variance 52

+     sig.level = 0.05,   # default is 0.05 (so you can skip this)

+     power = 0.90)       # and given power

     Balanced one-way analysis of variance power calculation 

         groups = 4
              n = 4.658128
    between.var = 33.33333
     within.var = 25
      sig.level = 0.05
          power = 0.9

 NOTE: n is number in each group

> # Hence, the required sample size is n = 5 (actual power

> # is higher).

>

> # The command below compute actual power when n = 5.

> power.anova.test(groups = 4,

+                  n = 5,   # actual sample size

+                  between.var = var(mu), within.var = 5^2)

     Balanced one-way analysis of variance power calculation 

         groups = 4
              n = 5
    between.var = 33.33333
     within.var = 25
      sig.level = 0.05
          power = 0.9270285

 NOTE: n is number in each group 

> # So, the actual power when n = 5 is 0.9270285.