I want to estimate the minimum detectable effect size for various levels of N and SD. Power is always fixed at 0.8 and alpha is always fixed at 0.05.
This is my code so far:
library(pwr)
power_fcn <- function(.x){
power.t.test(n = .x, d = NULL, power = 0.8, sig.level = 0.05, alternative = "two.sided")
}
power_df <-
map_dfr(
.x = seq(10000, 30000, by = 5000),
.f = power_fcn
)
But the above returns this error:
Error: Argument 1 must be a data frame or a named atomic vector.
but as far as I can see .x
is a vector...
What i'd like to be able to produce is something like this:
# A tibble: 5 x 5
n power sig.level test cohens_d
<dbl> <dbl> <dbl> <chr> <dbl>
1 10000 0.8 0.05 two-sided 0.0229
2 15000 0.8 0.05 two-sided 0.0323
3 20000 0.8 0.05 two-sided 0.0280
4 25000 0.8 0.05 two-sided 0.0251
5 30000 0.8 0.05 two-sided 0.0229
ideally with options to the function to add another column which converts the cohen's d into the units of the variable I care about (i.e. by passing through the SD).