Skip to contents

pwranova is an R package for power analysis in ANOVA designs, including between-, within-, and mixed-factor designs, with full support for both main effects and interactions across any number of factors.

The package allows calculation of statistical power, required total sample size, significance level, and minimal detectable effect sizes expressed as partial eta squared (ηp2\eta^2_p) 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 Pearson correlation tests, making the package a convenient toolkit for power analysis in experimental psychology and related fields.

For designs supported by G*Power (Faul et al., 2009), a widely used software tool for statistical power analysis, the results are identical to those produced by G*Power. The package also supports more flexible ANOVA designs and additional options for some related tests that are not available in G*Power.

Installation

The stable release of pwranova is available on CRAN:

install.packages("pwranova")

You can also install the development version from GitHub:

# Install devtools if not already installed
if (!requireNamespace("devtools", quietly = TRUE)) {
  install.packages("devtools")
}

# Install pwranova
devtools::install_github("mutopsy/pwranova")

Dependencies

  • R (>= 4.1.0)

No heavy external dependencies are required for the core functionality.

Quick start

library(pwranova)

### 1) Compute power (given N, effect size, alpha)

# One between factor (3 levels), no within factor
res_power_between <- pwranova(
  nlevels_b = 3,
  n_total   = 60,
  cohensf   = 0.25,
  alpha     = 0.05
)
res_power_between # returns power = 0.374

# One within factor (4 levels), no between factor
# (Optionally set epsilon for sphericity correction; default is 1)
res_power_within <- pwranova(
  nlevels_w = 4,
  n_total   = 30,
  cohensf   = 0.50,
  alpha     = 0.05,
  epsilon   = 1.00
)
res_power_within # returns power = 0.601

# Mixed design: one between factor (2 levels) and two within factors (2 and 3 levels)
# Show only a selected term with `target` if you want a compact output
res_power_mixed <- pwranova(
  nlevels_b = 2,
  nlevels_w = c(2, 3),
  n_total   = 30,
  cohensf   = 0.50,
  alpha     = 0.05,
  epsilon   = 1.00,
  target    = "B1:W2"  # show only 2x3 interaction of the between factor and the second within factor 
)
res_power_mixed # returns power = 0.663

### 2) Solve required total N (given target power)

# One between factor (3 levels), no within factor
res_n_between <- pwranova(
  nlevels_b = 3,
  cohensf   = 0.25,
  alpha     = 0.05,
  power     = 0.80
)
res_n_between  # returns required total N (multiple of the number of groups) = 159

# Interaction of two within factors (2 and 4 levels)
# Show only a selected term with `target` if you want a compact output
res_n_within <- pwranova(
  nlevels_w = c(2, 4),
  peta2     = 0.35, # effect size specified as partial eta squared (instead of Cohen's f)
  alpha     = 0.05,
  power     = 0.85,
  target    = "W1:W2" # show only 2x4 interaction 
)
res_n_within # returns required total N = 25

### 3) Planned contrast power

# Contrast weights must sum to 0
res_n_contrast <- pwrcontrast(
  weight  = c(1, -1, 0),  # three conditions, compare 1 vs 2
  paired  = FALSE,
  cohensf = 0.25,
  alpha   = 0.05,
  power = 0.80
)
res_n_contrast # returns required total N = 129

Key arguments

Below we summarize the key arguments of the main functions pwranova() and pwrcontrast(). Other power-analysis functions in the package follow a similar interface.

pwranova()

The key arguments of pwranova() used to specify the ANOVA design and the quantity to be solved are summarized below.

Argument Meaning Constraints Example
nlevels_b Numbers of levels for between-subjects factors integer ≥ 2 (scalar or vector) 3, c(2,4)
nlevels_w Numbers of levels for within-subjects factors integer ≥ 2 (scalar or vector) 3, c(2,4)
n_total Total sample size across all groups positive integer 60
alpha Significance level (0, 1) 0.05
power Desired statistical power (0, 1) 0.80
cohensf Cohen’s f > 0 0.25
peta2 Partial eta squared (ηp2\eta^2_p) (0, 1) 0.06

Exactly one of n_total, an effect size (cohensf / peta2), alpha, or power must be NULL. The missing quantity is solved from the others.

The returned object is a data frame including ANOVA terms, degrees of freedom, total sample size, alpha, power, effect sizes, and other computed quantities. For advanced usage, n_total, alpha, power, and the effect-size arguments may also be specified as vectors whose length matches the number of ANOVA terms (e.g., main effects or interactions).

pwrcontrast()

The key arguments of pwrcontrast() used to specify the contrast weights and the design are summarized below.

Argument Meaning Constraints Example
weight Contrast weights Numeric vector whose sum must be zero c(1,-1,0), c(3,-1,1,3)
paired Whether the design is paired Logical FALSE, TRUE
n_total Total sample size across all groups positive integer 60
alpha Significance level (0, 1) 0.05
power Desired statistical power (0, 1) 0.80
cohensf Cohen’s f > 0 0.25
peta2 Partial eta squared (ηp2\eta^2_p) (0, 1) 0.06

Exactly one of n_total, an effect size (cohensf / peta2), alpha, or power must be NULL. The missing quantity is solved from the others.

The returned object is a data frame including the specified weights, degrees of freedom, total sample size, alpha, power, effect sizes, and other computed quantities.

Functions

Current functions include:

  • pwranova() — Power analysis for between-, within-, and mixed-factor ANOVA, covering all main effects and interactions.
  • pwrcontrast() — Power analysis for a single planned contrast (1 df) in between-subjects or paired/repeated-measures designs.
  • pwrttest() — Power analysis for t-tests (one-sample, paired, and two-sample).
  • pwrcortest() — Power analysis for Pearson’s correlation (using either the t-distribution or Fisher’s z-transformation approach).

For full documentation, see the reference site (pkgdown): https://mutopsy.github.io/pwranova/reference/

Citation

Please cite the following preprint when using this package:

Muto, H. (2025). pwranova: An R package for power analysis of flexible ANOVA designs and related tests. Jxiv. https://doi.org/10.51094/jxiv.1555

Version history

See the changelog: https://mutopsy.github.io/pwranova/news/

Support

If you encounter a bug or would like to request a feature, please open an issue on GitHub: https://github.com/mutopsy/pwranova/issues

When reporting a bug, please include a minimal reproducible example if possible.

For questions about usage, feel free to open an issue as well.

License

GPL-3

References

Faul, F., Erdfelder, E., Buchner, A., & Lang, A.-G. (2009). Statistical power analyses using G*Power 3.1: Tests for correlation and regression analyses. Behavior Research Methods, 41(4), 1149–1160. https://doi.org/10.3758/BRM.41.4.1149