I am trying to calculate the sample size for a mixed linear regression model. The dependent variable is continuous and the model includes 2 further continuous variables. The random intercept is based on a grouping variable (5 levels reflecting sites where the subjects have been enrolled). I would like to calculate the proper sample size based on given Y (better if %change of Y rather than mean(SD), since I have this data from literature), given X (each unit change of it) using the mixed linear regression model I have already used but solving by N (alpha= 0.05 and beta= 0.20).

Is it possible using R?


The best way to do a sample size / power calculation for mixed models is via simulation. This entails the following steps:

  1. You simulate from the given design of interest. This will specify among others the number of groups/clusters/subjects and the number of measurements per cluster.
  2. You fit the model and perform the hypothesis testing of interesting and store the p-value.
  3. You repeat Steps 1-2, say 1000 times. The proportion of times the p-values were statistically significant in a pre-chosen significance level $\alpha$ is the estimated power for this specific design.

You could then go back and change some of the parameters of the design. E.g., increase the number of subjects or increase the number of measurements per cluster. Some of these calculations are streamlined in the simr package in R.


The following paper might be of help to you: Brysbaert, M., & Stevens, M. (2018). Power analysis and effect size in mixed effects models: A tutorial. Journal of cognition, 1(1).

Subsequently, cited within this paper is an online calculator for random targets and participants: https://jakewestfall.shinyapps.io/two_factor_power/


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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