emmeans_power: Compute power for 'emmeans' contrasts

View source: R/emmeans_power.R

emmeans_powerR Documentation

Compute power for emmeans contrasts


Computes power based on t value and degrees of freedom for contrasts. Do not use to calculate "observed power" for empirical datasets (Hoenig & Heisey, 2001).


emmeans_power(x, ...)

## S3 method for class 'emmGrid'
emmeans_power(x, ...)

## S3 method for class 'summary_em'
emmeans_power(x, ...)

## S3 method for class 'data.frame'
  alpha_level = Superpower_options("alpha_level"),
  liberal_lambda = Superpower_options("liberal_lambda"),



emmGrid. Grid of contrasts to estimate power from.


Other arguments passed to the function if object is not already a emmGrid object.


Alpha level used to determine statistical significance


Logical indicator of whether to use the liberal (cohen_f^2\*(num_df+den_df)) or conservative (cohen_f^2\*den_df) calculation of the noncentrality (lambda) parameter estimate. Default is FALSE.


Note that calculation of power is based on the F- and t-ratio assuming two-sided testing. Thus, the function does not honor adjustments of the testing procedure due to either one-sided testing (or two-one sided tests) or corrections for multiple comparisons via the p.adjust option in emmeans.

Power for one-sided tests can be calculated, if the means of the simulated dataset are consistent with the directional hypothesis, by doubling alpha_level. Similarly, power for Bonferroni-corrected contrasts can be calculated by adjusting alpha_level accordingly (see examples). ... Other arguments passed onto the function


Returns dataframe with simulation data (power and effect sizes!), anova results and simple effect results, plot of exact data, and alpha_level. Note: Cohen's f = sqrt(pes/1-pes) and the noncentrality parameter is = f^2*df(error)


A dataframe of the simulation result.


aov object returned from aov_car.


emmeans object returned from emmeans.


The power analysis results for ANOVA level effects.


The power analysis results for the pairwise (t-test) comparisons.


The power analysis results of the pairwise comparison results.


Default is "NULL". If a within-subjects factor is included, then the power of the multivariate (i.e. MANOVA) analyses will be provided.


The alpha level, significance cut-off, used for the power analysis.


Record of the function used to produce the simulation


A plot of the dataframe from the simulation; should closely match the meansplot in ANOVA_design


Frederik Aust


Hoenig, J. M., & Heisey, D. M. (2001). The Abuse of Power. The American Statistician, 55(1), 19–24. https://doi.org/10.1198/000313001300339897


## Not run: 
# Set up a within design with 2 factors, each with 2 levels
design_result <- ANOVA_design(design = "2w*2w",
n = 40, mu = c(1, 0, 1, 0),
sd = 2, r = 0.8,
labelnames = c("condition", "cheerful",
 "sad", "voice", "human", "robot"))
exact_result <- ANOVA_exact(design_result, 
alpha_level = 0.05, verbose = FALSE, 
emm = TRUE, contrast_type = "pairwise")

# Power for pairwise contrasts

# Corresponding emmeans contrasts

# Manually recalculate power
alpha_level = 0.05)

# Calculate power for Bonferroni-adjusted pairwise comparisons
n_contrasts <- nrow(as.data.frame(exact_result$emmeans$contrasts))
alpha_level = 0.05 / n_contrasts)

# Calculate power for one-sided custom contrasts
custom_contrast <- contrast(exact_result$emmeans$emmeans, 
list(robot_vs_sad_human = c(0, 1, -0.5, -0.5)))
 alpha_level = 0.05 * 2)

# Calculate power for follow-up ANOVA
follow_up <- joint_tests(exact_result$emmeans$emmeans, 
by = "condition")
alpha_level = 0.05 / 2)
pairwise ~ voice | condition)$contrasts, 
alpha_level = 0.05 / 2)

## End(Not run)

Superpower documentation built on May 17, 2022, 5:08 p.m.