2
$\begingroup$

Here are the libraries

library(tidyverse)
library(lmer4)

I'm using the data that comes with it: sleepstudy.

The example in the vignette is...

fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)

This works fine! Hooray! I'm excited because my data has the same form. Essentially, I have within-subjects design where participants see two versions of something. Participants rate each one. This leaves me with two ratings for each participant, one for each version. Hence, I apply this model to my work:

mymodel <- lmer(Rating ~ Version + (Version | Subject), mydata)

This results in an error:

Error: number of observations (=2600) <= number of random effects (=2600) for term (Accuracy | id); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable

I think that it must be my data, but decide to try to my the sleepsubject data similar to mine by reducing the number of days from 8 levels to 2, like mine:

sleepstudy2 <- sleepstudy %>% filter(Days < 2)

I then rerun the analysis:

fm2 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy2)

Same error:

Error: number of observations (=36) <= number of random effects (=36) for term (Days | Subject); the random-effects parameters and the residual variance (or scale parameter) are probably unidentifiable

Someone referencing a different problem here said,

15 unique IDs times (intercept + slope) gives 30 random effects. You don't have sufficient observations to support the model.

This would seem to be the logic behind my issue, but I'm confused why this problem doesn't become worse with the more levels in the nested variable (e.g., day).

So, back to the original question: Can a repeated measures variable with only 2 levels be nested within participants in lmer function?

$\endgroup$

1 Answer 1

3
$\begingroup$

I don't think it is your data, Derek - I obtained a similar error message when working with a different data set in the recent past. I think lmer() just can't handle this specific setting with 2 observations per subject for a continuous outcome variable. It's strange that lmer() would have this limitation and that the limitation hasn't yet been addressed by the lme package developers.

You can try using a function from another R package to fit your model. For example, the nlme package contains the lme() function which works for the example you provided:

sleepstudy01 <- subset(sleepstudy, Days %in% 0:1) 

head(sleepstudy01, 20)

library(nlme)

fm01lme <- lme(Reaction ~ Days, random = ~ Days | Subject, 
               method = "REML", data = sleepstudy01)

summary(fm01lme)
$\endgroup$
1
  • 4
    $\begingroup$ If Days takes only two values, then we have bivariate data. Hence, the marginal covariance matrix is $2\times2$ having three unique parameters. If you specify a model with random intercepts and random slopes with an unstructured covariance matrix, then you have four parameters in total, i.e., three in the covariance matrix of the random effects and the variance of the error terms leading to unidentifiable model. If however Days takes more than two distinct values but still all subjects have two measurements, you won’t have a problem. $\endgroup$ Commented Jun 30, 2019 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.