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

Jonathan Baron baron at psych.upenn.edu
Wed Aug 19 19:52:58 CEST 2009

Since nobody has answered yet, let me try.  I'm not 100% sure.  (So
why bother?  To check my own understanding.)

On 08/18/09 20:47, Jason R. Finley wrote:
> 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?)

I think that the first way assumes correlations of IV1, IV2, and the
Subject intercept.  The second way assumes that each of IV1 and IV2 is
correlated with the Subject intercept, and the intercept is computed
separately for IV1 and IV2.

There are other ways.  You can do, for example, 

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

This assumes, I think, that intercepts and slopes are uncorrelated.
If you can tolerate that assumption, an advantage of doing it this way
is that you can use mcmc sampling, and thus you can use pvals.fnc() in
the languageR package.  (What I do not know are the consequences of
making this assumption if it is false.)

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

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

Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron

More information about the R-help mailing list