1

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

It is to be noted that we are fixing the variance (see previous question: Fixing variance values in lme4). Hence, we do not need to estimate the variance.

Community
  • 1
  • 1
Philippe Massicotte
  • 1,321
  • 12
  • 24
  • Does this solve your problem? http://stats.stackexchange.com/questions/116475/why-do-i-get-the-error-message-error-grouping-factors-must-have-1-sampled-le – Travis Heeter Jan 03 '17 at 15:53
  • 1
    No, that's not possible. You can't estimate a variance from one value. – Roland Jan 03 '17 at 17:51
  • I should specify that we are fixing the variance (see previous question: http://stackoverflow.com/questions/39718754/fixing-variance-values-in-lme4). Hence, we do not need to estimate it. – Philippe Massicotte Jan 04 '17 at 14:13
  • Random effects models are used when you want to be able to generalize across a population of random groups where you assume the observed groups are a subset of possible groups. In this case, you're not doing that. The use of a random effects model isn't justified.

    The use case you mention likely requires custom code to move between standard `lm` and RE models
    – alexwhitworth Jan 04 '17 at 17:16
  • 1
    This is not a programming question, better chances at CrossValidated. – catastrophic-failure Jan 05 '17 at 02:35

0 Answers0