# Fit a linear mixed model with only 1 group

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)

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

• Why do you need this? Jan 6, 2017 at 7:05

Such a model is unidentifiable, because there's no way to distinguish the single random intercept from the model's overall intercept. Instead, say lm(Reaction ~ Days, ss).
• @Roland I think lmer does the right thing here. It's better to alert the analyst that a model is unidentifiable than to silently change it so it's identifiable. Jan 6, 2017 at 17:25