Adaptive simulation search for the per-between-cell sample size needed to
reach a requested power for a balanced factorial ANOVA design. The search
doubles upward from n_start until it brackets the target or reaches
n_max, then bisects the bracket.
Usage
power_n(
between = NULL,
within = NULL,
term,
target_pes,
power = 0.8,
n_sims = 10000,
alpha = 0.05,
ss_type = "III",
n_start = NULL,
n_max = 1000,
tol = 0.01,
gpower = FALSE,
progress = interactive(),
parallel = FALSE,
cores = NULL,
seed = NULL
)Arguments
- between
Named integer vector of between-subject factor level counts, e.g.
c(group = 2). UseNULLfor no between-subject factors.- within
Named integer vector of within-subject factor level counts, e.g.
c(time = 3, condition = 4). UseNULLfor no within-subject factors.- term
Character scalar naming the ANOVA term to test, e.g.
"group:time". Interaction terms are order-insensitive;"time:group"resolves to"group:time"when that is the design's factor order.- target_pes
Target partial eta squared for
term.- power
Desired target power.
- n_sims
Number of simulated datasets per sample size.
- alpha
Significance threshold.
- ss_type
Sums-of-squares type for the tested ANOVA term.
"III"is the default for order-invariant tests in unbalanced designs. Use"I"to reproduce sequentialstats::aov()tests.- n_start
Starting sample size per between-subject cell. If
NULL, starts at the smallest value that can support empirical calibration for the requested design.- n_max
Maximum sample size per between-subject cell.
- tol
Stop when estimated power is within
tolofpower.- gpower
Logical; if
TRUE, calibrate means to the G*Power-style noncentrality conventionlambda = total_n * f^2. The defaultFALSEcalibrates the empirical reference dataset totarget_pes, equivalent tolambda = den_df * f^2for the fitted ANOVA.- progress
Logical; if
TRUE, show a text progress bar.- parallel
Logical; if
TRUE, run simulations for each sample size via thefutureecosystem.- cores
Optional positive integer number of cores to use when
parallel = TRUE. IfNULL, uses one fewer than the number of available cores, with a minimum of one.- seed
Optional integer seed for reproducibility.