问题描述
我有一个data.frame
,df
:
> str(df_ss)
'data.frame': 571 obs. of 4 variables:
$ final_grade : num 0.733 0.187 0.502 0.194 0.293 ...
$ time_spent : num -0.2 -0.326 -0.709 -0.168 -0.254 ...
$ gender_female: num 1 0 1 0 0 0 1 1 1 1 ...
$ course_ID : Factor w/ 26 levels "1","2","3","4",..: 14 18 13 21 24 15 3 24 9 13 ...
我正在尝试查看time_spent
如何缓和gender_female
和final_grade
之间的关系.我为course_ID
指定了随机效果.
I am trying to see how time_spent
moderates the relationship between gender_female
and final_grade
. I'm specifying a random effect for course_ID
.
我指定使用的模型如下:
The models I specified using are as follows:
med.fit <- lme4::lmer(time_spent ~ gender_female + (1|course_ID), data = df)
out.fit <- lme4::lmer(final_grade ~ time_spent + gender_female + (1|course_ID), data = df_ss)
那些似乎工作正常.
以下示例使用lme4
包在小插曲(对于mediation
软件包),我指定了此中介模型:
Following an example using the lme4
package in a vignette for the mediation
package, I specified this mediation model:
library(mediation)
med.out <- mediate(med.fit, out.fit, treat = "gender_female", mediator = "time_spent", dropobs = T)
这导致此错误输出:Error in mediate(med.fit, out.fit, treat = "gender_female", mediator = "time_spent",: mediator model is not yet implemented
.
每个此邮件列表问题(和答案),我检查了这一点
Per this mailing list question (and answer), I checked that:
-
inherits(mediatorModel, "merMod")
返回了TRUE
和 -
getCall(mediatorModel)[[1]]
返回了lme4::lmer
inherits(mediatorModel, "merMod")
returnedTRUE
andgetCall(mediatorModel)[[1]]
returnedlme4::lmer
推荐答案
而不是lme4::lmer
,您可以尝试使用library(lme4)
加载lme4
,然后直接调用lmer
.查看mediate
代码表明错误处理检查正在寻找lmer
的精确匹配,即getCall(model.m)[[1]] == "lmer"
.
Instead of lme4::lmer
, you might try loading lme4
using library(lme4)
, then just call lmer
. Looking at the mediate
code shows that the error-handling checks are looking for an exact match for lmer
i.e. getCall(model.m)[[1]] == "lmer"
.
这篇关于在lme4模型中使用中介包时出错:中介器模型尚未实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!