Simulation-Based Power Analysis

A quick-start guide to simulation-based power analysis for mixed effects models, in R, Python, and Stata
Authors

Steve Worthington

Dan Yuan

Published

September 4, 2026

Introduction

This tutorial is designed to be a quick-start guide for conducting simulation-based power analyses in R, Python, and Stata. We focus particularly on power for mixed effects models, but the principles employed can be repurposed for any model and study design. The tutorial is suitable for anyone with an intermediate understanding of mixed effects models and coding in either R, Python, or Stata.

While high-level packages exist in some of these languages for conducting simulation-based power analysis (e.g., the R packages {simr}, {longpower}, and {simglm}), such packages abstract away the details of conducting simulations and thus are best used after gaining an understanding of the power simulation process. In addition, rolling your own simulations from scratch provides much more flexibility to tackle different study designs and models - and it’s fun!

Suggestions and feedback are welcome: use the Request help button at the top of the page.

Table of Contents

  1. Canned Power Analysis
  2. Simulation-based Power Analysis
  3. Power of What?
  4. R Examples
  5. Python Examples
  6. Stata Examples
  7. Resources

Contributors

A collaborative effort from the Data Science Services team at the Institute for Quantitative Social Science, Harvard University, with feedback from Jinjie Liu and Noah Greifer.