Skip to content

Instantly share code, notes, and snippets.

@JimGrange
Created November 29, 2021 11:31
Show Gist options
  • Save JimGrange/c1212059519cd7820482f079194d8c51 to your computer and use it in GitHub Desktop.
Save JimGrange/c1212059519cd7820482f079194d8c51 to your computer and use it in GitHub Desktop.
Power analysis to support EPS small grant submission
library(tidyverse)
library(Superpower)
# set means & standard deviations for idealised data
# (note experiment 1 data comes from the pilot experiment)
exp_1_means <- c(1334, 1594, 1588, 1725)
exp_1_sds <- c(308, 295, 338, 343)
exp_2_means <- c(1030, 1080, 1120, 1150)
exp_2_sds <- c(200, 200, 200, 200)
# plot the idealised data at population level
pd <- position_dodge(0.4)
tibble(
csi = c("short", "short", "short", "short",
"long", "long", "long", "long"),
response = c("rep", "rep", "sw", "sw",
"rep", "rep", "sw", "sw"),
stimulus = c("rep", "sw", "rep", "sw",
"rep", "sw", "rep", "sw"),
rt = c(exp_1_means, exp_2_means),
sd = c(exp_1_sds, exp_2_sds)) %>%
ggplot(aes(x = response, y = rt, group = stimulus)) +
geom_point(aes(colour = stimulus),
position = pd) +
geom_errorbar(aes(colour = stimulus,
ymax = rt + sd,
ymin = rt - sd),
position = pd) +
geom_line(aes(colour = stimulus),
position = pd) +
facet_wrap(~csi) +
theme_bw()
# power analysis
test <- Superpower::ANOVA_design(
design = "2w*2w*2w",
n = 100,
mu = data$rt,
sd = data$sd,
r = 0.80,
labelnames = c("csi", "short", "long",
"response", "rep", "sw",
"stimulus", "rep", "sw")
)
result <- Superpower::ANOVA_power(test, nsims = 10000)
# Power and Effect sizes for ANOVA tests
# power effect_size
# anova_csi 100.00 0.92040
# anova_response 100.00 0.71464
# anova_stimulus 100.00 0.66611
# anova_csi:response 100.00 0.30111
# anova_csi:stimulus 100.00 0.46830
# anova_response:stimulus 98.67 0.15790
# anova_csi:response:stimulus 85.16 0.09256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment