Hello stackexchange community! I am new to mixed-effects modelling (MEM) or mixed-models. In order to gain a better understanding of MEM, I decided to replicate two examples in R (lme4 package) from the textbook "Experimental Design and Analysis" by Dr. Howard J. Seltman. In the textbook, the author used SPSS to solve the two examples and included the relevant output tables.
Model 1, referred to as video game example, models "the linear relationship between trial and score with separate intercepts and slopes for each age group, and including a random per-subject intercept." The data for the video game example is available at the link below: https://www.stat.cmu.edu/~hseltman/309/Book/data/MMvideo.txt
The model 1 output tables are found on the page no. 370/382 (actual book/pdf book) of the textbook which is also linked below (or see image): https://www.stat.cmu.edu/~hseltman/309/Book/Book.pdf
My model 1 (video game example) is:
lmer(score ~ trial + (1|id) + (1+agegrp|agegrp), data=data)
where, trial is a fixed-effect. (1|id) is a random per-subject intercept. (1+agegrp|agegrp) is a random slope and random intercept for each age group.
The model 1 returns an error: boundary (singular) fit: see help('isSingular')
Model 2, referred to as classroom example, includes "main effects for stdTest, grade level, and treatment group" and "random effect (intercept) to account for school to school differences that induces correlation among scores for students within a school." Link for the classroom example data is included below: https://www.stat.cmu.edu/~hseltman/309/Book/data/schools.txt
The model 2 output tables are found on the page no. 377/391 (actual book/pdf book) of the textbook which is also linked below (or see image): https://www.stat.cmu.edu/~hseltman/309/Book/Book.pdf
My model 2 (classroom example) is:
lmer(score ~ stdTest + grade + treatment + (1|student) + (1|student:classroom), data=data)
where, stdTest, grade level, and treatment group are the fixed-effect. (1|student) is a random effect (intercept). (1|student:classroom) for students nested within a school.
The model 2 returns an error: number of levels of each grouping factor must be < number of observations (problems: student, classroom:student)
Could someone please help me model these two examples correctly to produce the desired outputs? Thank you, in advance, for your help.