In R, is it possible to force a lmer model with random effect to be fitted on data with only one level? We want to do this to keep the same model structure in rare case where our data only contains 1 grouping level. In a previous step, we manually fix variance of the random effects (https://stackoverflow.com/questions/39718754/fixing-variance-values-in-lme4), hence we do not need to estimate it.
The objective is not to estimate the variance components of the mixed model, but to estimate how pre-specified variances for a number of random factors affect the standard error of a mean value. For example, if $Y = \mu + A + B + C + \epsilon$ and we know (from other analyses) $V[A], V[B], V[C]$ and $V[\epsilon]$ then what is the variance of our estimate of $\mu$ when estimated from a data set that also contains information on the levels of the random factors $A, B$ and $C$? Hopefully, there is an easy way with lmer()
or at least getting the design matrix for the random factors out so that the covariance structure for all the random components can be calculated.
For information, this can be done easily in SAS with the hold-option to the parms statement in PROC MIXED, but apparently this is not as easily done in lmer().
The following illustrate the error.
library(lme4)
#> Loading required package: Matrix
sleepstudy$Subject <- as.character(sleepstudy$Subject)
ss <- sleepstudy[sleepstudy$Subject == "308", ]
m1 <- lmer(Reaction ~ Days + (1 | Subject), ss)
#> Error: grouping factors must have > 1 sampled level