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?
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