如何在lme中分别拟合两个随机效果? [英] How to fit two random effects separately in lme?
问题描述
我正在nlme软件包中通过REML进行线性混合效果模型拟合.这些是对我有用的代码:
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?
推荐答案
我认为可以使用lme()
通过以下代码分别包含两种随机效果(一种用于说话者,一种用于时间):
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),
和id
是一个更高级别的变量,其中同时嵌套了speaker
和item
.如果没有这样的变量,则可以将其作为所有变量的值为1的新变量引入.
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.
这篇关于如何在lme中分别拟合两个随机效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!