[R] lmer with random slopes for 2 or more first-level factors?

Jason R. Finley jrfinley at uiuc.edu
Wed Aug 19 03:47:28 CEST 2009

I have data from a design in which items are completely nested within  
subjects.  Subject is the only second-level factor, but I have  
multiple first-level factors (IVs).  Say there are 2 such independent  
variables that I am interested in.  What is the proper syntax to fit a  
mixed-effects model with a by-subject random intercept, and by-subject  
random slopes for both the 2 IVs?

I can think of at least two possibilities:

lmer(DV ~ IV1 + IV2 + (1 + IV1 + IV2 | Subject))

lmer(DV ~ IV1 + IV2 + (1 + IV1 | Subject) + (1 + IV2 | Subject))

Or maybe there is some other way to do it?  Maybe the correct syntax  
depends on whether the random effect of subjects on the intercept and  
slopes are correlated or not?  (If so, how do I proceed?)

Finally, what would be the syntax if I wanted to include a random  
subject effect for the INTERACTION of IV1 and IV2?

Thanks very much,

PS: additional search terms: multi-level linear model, MLM,  
hierarchical, repeated measures

Jason R. Finley
Department of Psychology
University of Illinois, Urbana-Champaign

More information about the R-help mailing list