Reputation: 11
I'm trying to find out what the minimal sample size is for an ANCOVA I need to run for my experiment, the experiment includes 5 different abiotic measurements from 6 different fields (as in, an actual field outside, not a 'scientific field'). In order to assess the minimum amount of observations I would need per field I want to perform a power calculation, for this purpose I'm currently thinking of using Shieh et al., (2020)'s method using the package 'Superpower' and the function 'power_oneway_ancova'. It looks like this:
power_oneway_ancova(
mu = c(400,450,500),
n_cov = 3,
sd = 100,
r2 = .25,
alpha_level = .05,
#n = c(17,17,17),
beta_level = .2,
round_up = TRUE,
type = "exact")
Because I want to include scientifically relevant/ realistic means and standard deviations, I would have to manually input different sample sizes for every different measurement type in order to find what sample size results in a minimum power of 0.8, which seems really inefficient and time consuming. Does anyone know of a package that allows me to input a preferred power and infer minimum sample size from that? Or maybe does someone with better programming skills than I know of a way to somehow automate this process and have R run until it finds a sample size that results in a minimum power of 0.8?
Upvotes: 1
Views: 62
Reputation: 3973
As Ben's answer shows, your code as written already calculates the minimum sample size n
per group required to get >80% power, because beta_level
is 1 - power.
You can also show this graphically by computing the power for any desired range of sample sizes:
sample_sizes <- 10:20
powers <- sapply(sample_sizes, function(n) power_oneway_ancova(
mu = c(400,450,500),
n_cov = 3,
sd = 100,
r2 = .25,
alpha_level = .05,
n = rep(n, 3),
round_up = TRUE,
type = "exact")$power
)
plot(sample_sizes, powers, xlab = 'Sample size per group', ylab = 'Power (1 - beta)')
abline(h = 80, col = 'blue', lwd = 2)
The output shows that n = 17 per group is the smallest value above the "magic number" of 80%.
Upvotes: 2
Reputation: 226742
I think the function can already give you the answer you want. The beta_level = 0.2
argument specifies that for given alpha_level
, r2
, and specified means and SDs, you want a false-negative rate of at most 0.2 == a power of at least 0.8.
pp <- power_oneway_ancova(
mu = c(400,450,500),
n_cov = 3,
sd = 100,
r2 = .25,
alpha_level = .05,
beta_level = .2,
round_up = TRUE,
type = "exact")
print(pp)
In this output, the boldfaced values tell you the total sample size and sample sizes per condition required to get a power of at least 0.8 (= 1-beta_level
).
Power Calculation for 1-way ANCOVA dfs = 2, 45 N = 51 n = 17, 17, 17 n_cov = 3 mu = 400, 450, 500 sd = 100 r2 = 0.25 alpha_level = 0.05 beta_level = 0.1878274 power = 81.21726 type = exact
Upvotes: 3