Sample size calculation for linear regression model with random intercept 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?
 A: The best way to do a sample size / power calculation for mixed models is via simulation. This entails the following steps:

*

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

*You fit the model and perform the hypothesis testing of interesting and store the p-value.

*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.
A: 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/
