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. Like G*Power, all analyses assume balanced designs with equal cell sizes, as extending power calculations to unbalanced designs generally requires additional assumptions about group sizes and variance structures.

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).

Additional arguments such as epsilon and target are described in the pwranova() help page.

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.

Example use cases

Example 1: Higher-order interaction in a mixed ANOVA

Consider a visual search experiment investigating age-related differences in search efficiency. Participants search for a target item among distractors and indicate whether the target is present or absent. The study includes one between-participant factor, age group (young vs. older adults), and two within-participant factors: target presence (present vs. absent) and set size (8, 16, or 24 items), forming a 2 × 2 × 3 mixed design.

Suppose the primary research question concerns whether age-related differences in search efficiency depend on target presence. This corresponds to the three-way interaction among age group, target presence, and set size. Based on previous studies or theoretical expectations, the researcher anticipates an interaction effect of f = 0.25 (ηp2\eta^2_p = 0.059) and wishes to achieve 80% statistical power with a significance level of 0.05. To estimate the required sample size, the researcher uses pwranova() and specifies the numbers of factor levels (nlevels_b = 2 and nlevels_w = c(2, 3)), the expected effect size (cohensf = 0.25 or peta2 = 0.059), the significance level (alpha = 0.05), and the desired power (power = 0.80). Specifying target = "B1:W1:W2" restricts the output to the three-way interaction of interest, whereas omitting target returns results for all main effects and interactions. For the three-way interaction, the estimated required total sample size is 156 (78 participants per age group).

Example 2: Planned linear contrast in a one-way design

Consider a study examining whether increasing study time improves test performance. Participants are randomly assigned to one of four conditions: 0, 30, 60, or 90 minutes of study. The primary research question concerns whether performance increases linearly as study time increases.

This hypothesis can be tested using a planned linear contrast with weights c(-3, -1, 1, 3). Based on previous studies or theoretical expectations, the researcher anticipates a contrast effect of η2\eta^2 = 0.05 (f = 0.229) and wishes to achieve 80% statistical power with a significance level of 0.05. To estimate the required sample size, the researcher uses pwrcontrast() and specifies the contrast weights (weight = c(-3, -1, 1, 3)), the design (paired = FALSE), the expected effect size (cohensf = 0.229 or peta2 = 0.05), the significance level (alpha = 0.05), and the desired power (power = 0.80). With these specifications, pwrcontrast() estimates that a total sample size of 152 (38 participants per group) is required. If quadratic or cubic trends are of interest, alternative contrast weights can be specified (e.g., c(1, -1, -1, 1) for a quadratic trend or c(-1, 3, -3, 1) for a cubic trend). More generally, any user-defined contrast whose weights sum to zero can be analyzed.

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