# Estimation of maximum number of observations for lmer [closed]

From a previous topic(Maximum number of independent variables that can be entered into a multiple regression equation ) I am trying to extend the function into lmer for basic clinical psychology/neuropsychology studies with 2 factors (fact = time 1 and 2; fact2 = treatment 1 and 2), 1 continuous predictor and id (repeated 2 times as time is two levels) to compute minimum number of subjects to be included to explain each variable.

1 does this sound correct? 2 any improvements that might be useful?

fitlmer <- function(n, k) {
# n: sample size
# k: number of predictors
# return linear model fit for given sample size and k predictors
require(lme4)
require(lmerTest)
x <- data.frame(matrix(rnorm(n*k), nrow=n))
names(x) <- paste("x", seq(k), sep="")
x$y <- rnorm(n) x$fact <- rep(1:2)
x$fact2 <- rep(1:2, each= 2) x$id <- rep(1:(n/2), each= 2)
as.factor(x$fact) as.factor(x$fact2)
summary(lmer(y~x1*fact*fact2+ (1|id), data=x), ddf = "Kenward-Roger")
}