The package ‘Superpower’ is used due to its support for mixed designs (ours is a 2x2 within x between). We use medium effect size as justified in: Schmiedt-Fehr et al., 2016: DOI: 10.1016/j.clinph.2016.07.008, Reteig et al., 2019: 10.1016/j.cortex.2019.02.016.
library(Superpower)
## Warning: package 'Superpower' was built under R version 4.0.5
set.seed(2022)
mu <- c(-0.25, 0.25, 0.25, -0.25) #Cohen's f expected to be 0.25
#Justification: Schmiedt-Fehr et al., 2016: DOI: 10.1016/j.clinph.2016.07.008, Reteig et al., 2019: 10.1016/j.cortex.2019.02.016
#f value: Cohen, 1988
n <- 17 #Number of participants suggested by plotting
sd <- 1 #Typical parameters
r <- 0.5 #Typical parameters
string = "2w*2b" # 2 within x 2 between subjects
alpha_lev <- 0.05 #Desired alpha level
labelnames = c("age", "old", "young", "alpha", "low", "high") #Condition names
design_result <- ANOVA_design( #Design is compiled
design = string,
n = n,
mu = mu,
sd = sd,
r = r,
labelnames = labelnames
)
A simulation shows the cutoff point.
plot_power(design_result, min_n = 10, max_n = 250, desired_power = 80) # A simulation is run, the generated plot shows the cut-off point
## Achieved Power and Sample Size for ANOVA-level effects
## variable label n achieved_power desired_power
## 1 alpha Desired Power Not Reached 250 5.0 80
## 2 age Desired Power Not Reached 250 5.0 80
## 3 alpha:age Desired Power Achieved 17 80.7 80
Using n of 17, the simulation results in power above 80.
simulation_result <- ANOVA_power(design_result, #Simulation is confirmed 100x with n set to 17
alpha_level = alpha_lev,
nsims = 100,
verbose = FALSE,
seed = 2022)
final_power <- simulation_result[["main_results"]][["power"]][3]
simulation_result
## Power and Effect sizes for ANOVA tests
## power effect_size
## anova_alpha 6 0.03330
## anova_age 3 0.02505
## anova_alpha:age 81 0.22122
##
## Power and Effect sizes for pairwise comparisons (t-tests)
## power effect_size
## p_age_old_alpha_low_age_old_alpha_high 29 0.502695
## p_age_old_alpha_low_age_young_alpha_low 50 0.518962
## p_age_old_alpha_low_age_young_alpha_high 7 -0.009527
## p_age_old_alpha_high_age_young_alpha_low 5 0.014159
## p_age_old_alpha_high_age_young_alpha_high 57 -0.531962
## p_age_young_alpha_low_age_young_alpha_high 35 -0.530269
The power can be extracted from the model.
final_power #This is the power value found with n at 17
## [1] 81
```