0
$\begingroup$

I have a dataset with participants' scores on three exams. Each participant completed each of the three exams. So the dataset looks something like (for a total of 945 rows):

SubjectCode    Exam    Score
1              A       70
1              B       44
1              C       80
2              A       62
2              B       50
2              C       89

I can run the following model without problem, using the nlme library:

lme(LD ~ 1, random = ~1|SubjectCode/Exam, data = ld_melted, method = "ML")

However, when I try the same with the lme4 library, I get an error:

lmer(LD ~ 1 + (1|SubjectCode/Exam), data = ld_melted)

Error: number of levels of each grouping factor must be < number of observations

Firstly, I don't understand the error. My dataset consists of 945 rows: 315 students * 3 exams. So it would seem that "the number of levels of each grouping factor" is 315 for SubjectCode, and 3 for Exam, both of them lower then the number of observations (945).

Secondly, the GLMM FAQ states that model specifications are used both by lme4 and nlme. So I also don't understand why one, but not the other, throws an error.

Thanks for any help!

$\endgroup$
3
  • 1
    $\begingroup$ (1|SubjectCode/Exam) is equivalent to (1|SubjectCode) + (1|SubjectCode:Exam). The interaction SubjectCode:Exam has 945 levels and you have 945 rows. So lme4 is right in complaining. No idea why nlme does not. $\endgroup$
    – amoeba
    Commented Jul 2, 2018 at 16:03
  • $\begingroup$ Thanks, that's really helpful. What would in your opinion then be the correct way to specify this model, considering the fact that I have repeated measures? (This is supposed to be a null model without fixed effects; I'll add the fixed effects later when I know that the null model is correct) $\endgroup$
    – Johanna
    Commented Jul 2, 2018 at 16:07
  • 1
    $\begingroup$ LD ~ 1 + (1|SubjectCode). You don't need random effect for Student/Exam if you only have 1 observation per Student/Exam combination. $\endgroup$
    – amoeba
    Commented Jul 2, 2018 at 16:14

0

Your Answer

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

Browse other questions tagged or ask your own question.