Skip to content

Instantly share code, notes, and snippets.

@mcfrank
Created August 12, 2024 19:35
Show Gist options
  • Save mcfrank/9f2c432869fcad13a568d7ef43d79d4f to your computer and use it in GitHub Desktop.
Save mcfrank/9f2c432869fcad13a568d7ef43d79d4f to your computer and use it in GitHub Desktop.
library(tidyverse)
library(pwr)
pwrs <- expand_grid(n = seq(0, 100, 10),
es = seq(0, 1, .1)) |>
mutate(pwr = map2_dbl(es, n,
~pwr.t.test(d = .x, n = .y)$power))
ggplot(pwrs, aes(x = n, y = pwr, col = as.factor(es))) +
geom_line() +
geom_hline(yintercept = .8, lty = 2) +
geom_vline(xintercept = 72, lty = 2)
# https://humburg.github.io/Power-Analysis/simr_power_analysis.html
library(simr)
# make fake data
n <- 72
subj <- 1:n
age <- runif(n = n, min = 3, max = 6)
group <- c("noise", "no noise")
d <- tibble(subj = rep(subj, 2),
age = rep(age, 2),
condition = c(rep("noise", n), rep("no noise", n)))
## coefficients
rand <- list(0.5)
fixed <- c(0, 1)
## residual variance
res <- 2
#Create model
model <- makeGlmer(y ~ condition + (1|subj),
fixef = fixed, VarCorr=rand, data=d, family = "binomial" )
powerSim(model, nsim=100, test = fcompare(y~1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment