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?
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?
Share Improve this question asked Feb 14 at 14:20 brushyourteethbrushyourteeth 111 silver badge1 bronze badge 2- 2 Also be careful about design. You may have a split plot or similar experiment here. I suggest you seek advice. – Limey Commented Feb 14 at 18:48
- 1 Yes, you're right @Limey I did not notice that when I originally read this. Adding more observations per field is not going to increase your statistical power very much. Your power is more or less based on the number of fields you have. Multiple measurements from the same field are not independent of each other. – qdread Commented Feb 14 at 19:09
2 Answers
Reset to default 3I 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
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%.