How to fit two random effects separately in lme?

user3288202 picture user3288202 · Feb 8, 2014 · Viewed 17.8k times · Source

I'm doing Linear mixed-effects model fit by REML in nlme package. And these are codes that work for me:

# Linear mixed-effects model fit by REML (intercept and not slope)
x <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~1|speaker)
summary(x)

# Linear mixed-effects model fit by REML (slope and no intercept)
x1 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~IV3-1|speaker)
summary(x1)

# Linear mixed-effects model fit by REML (slope and intercept)
x2 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~IV3|speaker)
summary(x2)

#nested random effect
x5 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~1|speaker/item)
summary(x5)

What I really would like to do is having a model with both speaker and item as random effects separately. I had tried to use this formula:

x4 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~1|speaker + 1|item)

However, this formula gives me the following warning message:

Warning message:
In Ops.factor(speaker, 1) : + not meaningful for factors

Do you have any idea what this means? And how can I fit both speaker and item as random effects separately?

Answer

Fien picture Fien · Mar 30, 2016

I think it is possible to include two random effects seperately (one for speaker and one for time) using lme() by the following code:

x4 <- lme (DV ~ IV1 + IV2 + IV1*IV2, data=a.frame, random=~ speaker + item -1 | id),

with id a higher level variable in which both speaker and item are nested. If you don't have such a variable, you could introduce it as a new variable with value 1 for all observations.