本文介绍了在lme4模型中使用中介包时出错:中介器模型尚未实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个data.framedf:

> 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_femalefinal_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:

  1. inherits(mediatorModel, "merMod")返回了TRUE
  2. getCall(mediatorModel)[[1]]返回了lme4::lmer
  1. inherits(mediatorModel, "merMod") returned TRUE and
  2. getCall(mediatorModel)[[1]] returned lme4::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模型中使用中介包时出错:中介器模型尚未实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:36