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!
(1|SubjectCode/Exam)
is equivalent to(1|SubjectCode) + (1|SubjectCode:Exam)
. The interactionSubjectCode:Exam
has 945 levels and you have 945 rows. Solme4
is right in complaining. No idea whynlme
does not. $\endgroup$LD ~ 1 + (1|SubjectCode)
. You don't need random effect for Student/Exam if you only have 1 observation per Student/Exam combination. $\endgroup$