2
$\begingroup$

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

model 1 output tables (extracted from page no. 370 of "Experimental Design and Analysis" textbook by Dr. Howard J. Seltman)

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

model 2 output tables(extracted from page no. 377 of "Experimental Design and Analysis" textbook by Dr. Howard J. Seltman)

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

For Model 1, the author specified only a single random intercept for id and then a series of fixed intercepts and slopes corresponding to treatment, age group, and the interaction of age group and treatment. Note that to match the output in the text, you will need to recode the age group variable such that age group = (40,50) is the reference category.

# Recode agegrp (I assume that it is coded such that 0 = (20,30), 1 = (30,40) and 2 = (40,50) 
DF <- within(DF, agegrp <- relevel(agegrp, ref = 2)) 
m1 <- lmer(score ~ treatment*as.factor(agegrp) + (1|id), data = DF)

For model 2, you have only a single random intercept for classroom (I do not see school in the data file) and then fixed intercepts for grade and treatment and a fixed slope for stdtest. Again, for some reason the author has the factor variables coded such that grade 5 is the reference and treatment==1 is the reference, so you will need to recode (relevel) to exactly match their output.

m2 <- lmer(score ~ as.factor(grade) + as.factor(treatment) + stdtest + (1|classroom), data = DF2) 
$\endgroup$

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.