How to fit two random effects separately in lme?

萝らか妹 提交于 2019-12-04 11:56:30

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/21651879/how-to-fit-two-random-effects-separately-in-lme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!