Exercise 1

Redefine the function if necessary, then call the function with the provided arguments.

calc_Cohen_d <- function(xbar1, xbar2, s1, s2, n1, n2) {
  s <- sqrt(((n1 - 1) * s1^2 + (n2 - 1) * s2^2) / (n1 + n2 - 2))
  (xbar1 - xbar2) / s
}

calc_Cohen_d(xbar1 = 45, xbar2 = 35, s1 = 10, s2 = 5, n1 = 50, n2 = 100)
## [1] 1.416609

We get ~1.42, which is quite a large effect.

Exercise 2

wp.correlation(n = 50, r = c(0.2, 0.4, 0.6), alpha = 0.05)
## Power for correlation
## 
##      n   r alpha     power
##     50 0.2  0.05 0.2895186
##     50 0.4  0.05 0.8349864
##     50 0.6  0.05 0.9977493
## 
## URL: http://psychstat.org/correlation

Exercise 3

We use extend() to set up the simulation for 10 blocks. Next we generate each power curve with powerCurve(). The arguments are the same except the first argument to fixed(), which is 'nitro' for the main effect and 'gen:nitro' for the interaction effect. If you use the same random seed as in this code you should get the same results.

yates_lmm_extended <- extend(yates_lmm, along = 'block', n = 50)

yates_pcurve_maineffect <- powerCurve(yates_lmm_extended, 
                                      along = 'block', 
                                      test = fixed('nitro', method = 'f'), 
                                      nsim = 10, 
                                      seed = 1)

yates_pcurve_interaction <- powerCurve(yates_lmm_extended, 
                                       along = 'block', 
                                       test = fixed('gen:nitro', method = 'f'), 
                                       nsim = 10, 
                                       seed = 2)

The power curves indicate that for any number of blocks, we have nearly 100% power to detect a main effect of nitrogen fertilization on oat yield, but very low power to detect an interaction until the number of blocks is >30. The nitrogen fertilization effect is very strong but hardly varies by genotype. We can conclude that if the differences in genotype response to nitrogen observed in this dataset are close to the true differences, we would need an extremely high number of replicates to reliably detect that difference.

plot(yates_pcurve_maineffect)

plot(yates_pcurve_interaction)