I'm searching for a built-in function in R for calculating the required sample size (given certain power, alpha,..) of a mixed ANOVA (2 between, 1 within variable, 2x2x2 design). Does this function exist? I didn't find it in the following packages:

•pwr is the oldest power-analysis library; some introductory info can be found on Quick-R

•PoweR: Computation of power and level tables for hypothesis tests

•Power2Stage: Power and Sample size distribution of 2-stage BE studies via simulations

•powerAnalysis: Power analysis in experimental design

•powerGWASinteraction: Power Calculations for Interactions for GWAS

•powerMediation: Power/Sample size calculation for mediation analysis, simple linear regression, logistic regression, or longitudinal study

•powerpkg: Power analyses for the affected sib pair and the TDT design

•powerSurvEpi: Power and sample size calculation for survival analysis of epidemiological studies

•PowerTOST: Power and Sample size based on two one-sided t-tests (TOST) for (bio)equivalence studies

•longpower: Power and sample size for linear model of longitudinal data



1 Answer 1


I don't think a single function exists for your specific case. In fact once you move beyond the basics (those in your list above) any simple function would need to make several assumptions that you may or may not be happy with.

For more complex studies like this you can estimate power using simulation, and that way you control all the assumptions made instead of having to live with the assumptions of others.

The basic steps are:

  1. decide what you think your data will look like
  2. decide how you will analyze your data
  3. write a function that simulates your data and analyzes it and returns the p-value of interest (things that you want to explore, like sample size, should be arguments to the function)
  4. run your function a bunch of times for a given set of conditions
  5. the power is just the proportion of times that the p-value is less than alpha.
  6. repeat step 4 for a new set of conditions.

Here is an answer to a similar question with examples of calculating power by simulation using R.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.