Title: | Power Analysis of Flexible ANOVA Designs and Related Tests |
Version: | 1.0.2 |
Description: | Provides functions for conducting power analysis in ANOVA designs, including between-, within-, and mixed-factor designs, with full support for both main effects and interactions. The package allows calculation of statistical power, required total sample size, significance level, and minimal detectable effect sizes expressed as partial eta squared or Cohen's f for ANOVA terms and planned contrasts. In addition, complementary functions are included for common related tests such as t-tests and correlation tests, making the package a convenient toolkit for power analysis in experimental psychology and related fields. |
License: | GPL-3 |
Encoding: | UTF-8 |
URL: | https://github.com/mutopsy/pwranova, https://mutopsy.github.io/pwranova/ |
BugReports: | https://github.com/mutopsy/pwranova/issues |
RoxygenNote: | 7.3.2 |
Depends: | R (≥ 4.1.0) |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2025-10-01 04:59:07 UTC; owner |
Author: | Hiroyuki Muto |
Maintainer: | Hiroyuki Muto <mutopsy@omu.ac.jp> |
Repository: | CRAN |
Date/Publication: | 2025-10-07 18:30:09 UTC |
Convert Cohen's f to Partial Eta Squared
Description
Converts Cohen's f to partial eta squared (\eta_p^2
)
using the standard definition in Cohen (1988).
Usage
cohensf_to_peta2(f)
Arguments
f |
A numeric vector of Cohen's f values. Each value must be greater than or equal to 0. |
Details
The conversion is defined as:
\eta_p^2 = \frac{f^2}{1 + f^2}
This follows from the relationship: f = \sqrt{\eta_p^2 / (1 - \eta_p^2)}
Value
A numeric vector of partial eta squared values.
References
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsdale, NJ: Lawrence Erlbaum Associates.
See Also
Examples
# Convert a single Cohen's f value
cohensf_to_peta2(0.25)
# Convert multiple values
cohensf_to_peta2(c(0.1, 0.25, 0.4))
Convert Partial Eta Squared to Cohen's f
Description
Converts partial eta squared (\eta_p^2
) to
Cohen's f using the standard definition in Cohen (1988).
Usage
peta2_to_cohensf(peta2)
Arguments
peta2 |
A numeric vector of partial eta squared values. Each value must be within the range of 0 to 1. |
Details
The conversion is defined as:
f = \sqrt{\eta_p^2 / (1 - \eta_p^2)}
This follows from the inverse relationship:
\eta_p^2 = \frac{f^2}{1 + f^2}
Value
A numeric vector of Cohen's f values.
References
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsdale, NJ: Lawrence Erlbaum Associates.
See Also
Examples
# Convert a single partial eta squared value
peta2_to_cohensf(0.06)
# Convert multiple values
peta2_to_cohensf(c(0.01, 0.06, 0.14))
Power Analysis for Between-, Within-, or Mixed-Factor ANOVA
Description
Computes power, required total sample size, alpha, or minimal detectable effect size for fixed-effects terms in between-/within-/mixed-factor ANOVA designs.
Usage
pwranova(
nlevels_b = NULL,
nlevels_w = NULL,
n_total = NULL,
alpha = NULL,
power = NULL,
cohensf = NULL,
peta2 = NULL,
epsilon = 1,
target = NULL,
max_nfactor = 6,
nlim = c(2, 10000)
)
Arguments
nlevels_b |
Integer scalar or vector. Numbers of levels for
between-subjects factors. Omit or set |
nlevels_w |
Integer scalar or vector. Numbers of levels for
within-subjects factors. Omit or set |
n_total |
Integer scalar or vector. Total sample size across all groups.
If |
alpha |
Numeric in |
power |
Numeric in |
cohensf |
Numeric (non-negative). Cohen's |
peta2 |
Numeric in |
epsilon |
Numeric in |
target |
Character vector of term labels to compute (e.g., |
max_nfactor |
Integer. Safety cap for the total number of factors. |
nlim |
Integer length-2. Search range of total |
Details
Fixed-effects, balanced designs are assumed. All groups/cells have equal cell sizes and effects are tested with standard fixed-effects ANOVA models.
Numerator degrees of freedom for within-subjects terms with
\mathrm{df}_1 \ge 2
are adjusted by the nonsphericity parameterepsilon
.Denominator degrees of freedom follow standard mixed-ANOVA formulas and are multiplied by the same
epsilon
for within-subjects terms.Critical values are computed from the central F-distribution; power uses the noncentral F-distribution with noncentrality parameter
\lambda = f^2 \cdot n_{\mathrm{total}}
.Effect-size inputs can be given as Cohen’s
f
or partial eta-squared\eta_p^2
(internally converted viaf = \sqrt{\eta_p^2/(1-\eta_p^2)}
). If both areNULL
, the minimal detectable effect size is solved for givenn_total
,alpha
, andpower
.Exactly one of
n_total
, an effect-size specification (cohensf
/peta2
),alpha
, orpower
must beNULL
; that quantity is then solved.-
Validation against GPower: For the subset of designs supported by GPower (between-, within-, and mixed-factor ANOVA with equal cell sizes),
pwranova()
was validated to produce results identical to those of GPower.
Value
A data frame with S3 class:
-
"cal_power"
when power is calculated givenn_total
,alpha
, and effect size; -
"cal_n"
or"cal_ns"
whenn_total
is solved; -
"cal_alpha"
or"cal_alphas"
whenalpha
is solved; -
"cal_es"
when minimal detectable effect sizes are solved.
Columns include term
, df_num
, df_denom
, n_total
,
alpha
, power
, cohensf
, peta2
, F_critical
,
ncp
, epsilon
.
References
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsdale, NJ: Lawrence Erlbaum Associates.
Examples
# One between factor (k = 3), one within factor (m = 4), compute power
pwranova(nlevels_b = 3, nlevels_w = 4, n_total = 60,
cohensf = 0.25, alpha = 0.05, power = NULL, epsilon = 0.8)
# Solve required total N for target power
pwranova(nlevels_b = 2, nlevels_w = NULL, n_total = NULL,
peta2 = 0.06, alpha = 0.05, power = 0.8)
Power Analysis for Planned Contrast in Between- or Within-Factor ANOVA
Description
Computes power, required total sample size, alpha, or minimal detectable effect size for a single planned contrast (1 df) in between-participants or paired/repeated-measures settings.
Usage
pwrcontrast(
weight = NULL,
paired = FALSE,
n_total = NULL,
cohensf = NULL,
peta2 = NULL,
alpha = NULL,
power = NULL,
nlim = c(2, 10000)
)
Arguments
weight |
Numeric vector (length |
paired |
Logical. |
n_total |
Integer or integer vector. Total sample size(s). If |
cohensf |
Numeric (non-negative). Cohen's |
peta2 |
Numeric in |
alpha |
Numeric in |
power |
Numeric in |
nlim |
Integer length-2. Search range of total |
Details
For a contrast with weights w_1, \dots, w_K
that sum to zero,
the numerator df is 1. The denominator df is n - K
for
between-subjects (unpaired) designs and (n - 1)(K - 1)
for
paired/repeated-measures designs. Power uses the noncentral F-with
\lambda = f^2 \cdot n_{\mathrm{total}}
.
Contrast weights (
weight
) are not centered internally; only the zero-sum condition is enforced (up to numerical tolerance).When
paired = FALSE
, the total sample sizen_total
must be a multiple of the number of contrast groupsK
.Exactly one of
n_total
, an effect-size specification (cohensf
/peta2
),alpha
, orpower
must beNULL
; that quantity is then solved.Critical values are computed from the central F-distribution; power is based on the noncentral F-distribution with noncentrality parameter
\lambda = f^2 \cdot n_{\mathrm{total}}
.Effect-size inputs can be given as Cohen’s
f
or partial eta-squared\eta_p^2
(internally converted viaf = \sqrt{\eta_p^2/(1-\eta_p^2)}
). If both areNULL
, the minimal detectable effect size is solved for givenn_total
,alpha
, andpower
.
Value
A one-row data frame with class:
-
"cal_power"
when power is calculated givenn_total
,alpha
, and effect size; -
"cal_n"
whenn_total
is solved; -
"cal_alpha"
whenalpha
is solved; -
"cal_es"
when minimal detectable effect sizes are solved.
Columns: term
(always "contrast"
), weight
(comma-separated string),
df_num
, df_denom
, n_total
, alpha
, power
,
cohensf
, peta2
, F_critical
, ncp
.
References
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Hillsdale, NJ: Lawrence Erlbaum Associates.
Examples
# Two-group contrast (1, -1), between-subjects: compute power
pwrcontrast(weight = c(1, -1), paired = FALSE,
n_total = 40, cohensf = 0.25, alpha = 0.05)
# Four-level contrast (e.g., Helmert-like), solve required N for target power
pwrcontrast(weight = c(3, -1, -1, -1), paired = FALSE,
n_total = NULL, peta2 = 0.06, alpha = 0.05, power = 0.80)
# Paired contrast across K=3 conditions
pwrcontrast(weight = c(1, 0, -1), paired = TRUE,
n_total = NULL, cohensf = 0.2, alpha = 0.05, power = 0.9)
Power Analysis for Pearson Correlation
Description
Computes statistical power, required total sample size, \alpha
,
or the minimal detectable correlation coefficient for a Pearson correlation test.
Two computational methods are supported: exact noncentral t (method = "t"
)
and Fisher's z-transformation with normal approximation (method = "z"
).
Usage
pwrcortest(
alternative = c("two.sided", "one.sided"),
n_total = NULL,
alpha = NULL,
power = NULL,
rho = NULL,
method = c("t", "z"),
bias_correction = FALSE,
nlim = c(2, 10000)
)
Arguments
alternative |
Character. Either |
n_total |
Integer scalar. Total sample size ( |
alpha |
Numeric in |
power |
Numeric in |
rho |
Numeric correlation coefficient in |
method |
Character. Either |
bias_correction |
Logical. Applies only to |
nlim |
Integer vector of length 2. Search range of |
Details
Exactly one of
n_total
,rho
,alpha
, orpower
must beNULL
; that quantity is then solved.For
method = "t"
, computations are based on the noncentral t-distribution with noncentrality parameter\lambda = \tfrac{\rho}{\sqrt{1-\rho^2}} \sqrt{n}
.For
method = "z"
, computations use Fisher's z transformation of the population correlation,z_\rho = \operatorname{atanh}(\rho)
. LetW = \sqrt{n-3}\, z
. Under the alternative hypothesis,W \sim \mathrm{Normal}(\mu,\,1)
with\mu = \sqrt{n-3}\, z_\rho
. Ifbias_correction = TRUE
,\rho
is first bias-corrected before applying Fisher's transform. Critical values are taken from the central normal distribution underH_0:\rho=0
(i.e.,W \sim \mathrm{Normal}(0,1)
under the null). The returnedncp
equals\mu
.-
Validation against GPower: Results have been confirmed to match those produced by GPower for equivalent correlation tests using the noncentral t-distribution.
-
Note: Results from
method = "z"
will not exactly matchpwr::pwr.r.test
, becausepwr
uses a hybrid approach combining the Fisher-z approximation with a t-based critical value.
Value
A one-row data.frame
with class
"cal_power"
, "cal_n"
, "cal_alpha"
, or "cal_es"
,
depending on the solved quantity. Columns:
-
df
(only formethod = "t"
) -
n_total
,alpha
,power
-
rho
,t_critical
orz_critical
-
ncp
(noncentrality parameter or mean under the alternative: see Details)
Examples
# (1) Compute power for rho = 0.3, N = 50, two-sided test
pwrcortest(alternative = "two.sided", n_total = 50, rho = 0.3, alpha = 0.05)
# (2) Solve required N for target power, using Fisher-z method
pwrcortest(method = "z", rho = 0.2, alpha = 0.05, power = 0.8)
# (3) Solve minimal detectable correlation
pwrcortest(n_total = 60, alpha = 0.05, power = 0.9, rho = NULL)
Power Analysis for One-/Two-Sample and Paired t Tests
Description
Computes statistical power, required total sample size, \alpha
,
or the minimal detectable effect size for a t-test in one of three designs:
one-sample, two-sample (independent), or paired/repeated measures.
Usage
pwrttest(
paired = FALSE,
onesample = FALSE,
n_total = NULL,
alpha = NULL,
power = NULL,
delta = NULL,
cohensf = NULL,
peta2 = NULL,
alternative = c("two.sided", "one.sided"),
nlim = c(2, 10000)
)
Arguments
paired |
Logical. |
onesample |
Logical. |
n_total |
Integer scalar. Total sample size.
If |
alpha |
Numeric in |
power |
Numeric in |
delta |
Numeric (non-negative). Cohen's
If |
cohensf |
Numeric (non-negative). Cohen's
|
peta2 |
Numeric in |
alternative |
Character. Either |
nlim |
Integer vector of length 2. Search range of total |
Details
If multiple effect-size arguments are supplied (
delta
,cohensf
,peta2
), precedence isdelta
>
cohensf
>
peta2
; the rest are ignored with a warning.For the two-sample design, equal allocation is assumed;
n_total
must be even when provided, and the solvedn_total
will be an even number.For the paired design, the effect size is interpreted as
d_z
.Computations use the central and noncentral t-distributions (
stats::qt
,stats::pt
); root finding usesstats::uniroot()
where needed.Results have been validated to match those produced by G*Power for equivalent one-sample, paired, and two-sample t tests.
Value
A one-row data.frame
with class
"cal_power"
, "cal_n"
, "cal_alpha"
, or "cal_es"
,
depending on the solved quantity. Columns:
df
, n_total
, alpha
, power
,
delta
, cohensf
, peta2
,
t_critical
, ncp
.
Examples
# (1) Two-sample (independent), compute power given N and d
pwrttest(paired = FALSE, onesample = FALSE, alternative = "two.sided",
n_total = 128, delta = 0.50, alpha = 0.05)
# (2) Paired t-test, solve required N for target power
pwrttest(paired = TRUE, onesample = FALSE, alternative = "one.sided",
n_total = NULL, delta = 0.40, alpha = 0.05, power = 0.90)
# (3) One-sample t-test, solve alpha given N and power
pwrttest(onesample = TRUE, alternative = "two.sided",
n_total = 40, delta = 0.40, alpha = NULL, power = 0.80)
# (4) Two-sample, specify effect via f or partial eta^2 (converted internally)
pwrttest(paired = FALSE, cohensf = 0.25, n_total = NULL, alpha = 0.05, power = 0.80)