问题
I have a 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 ...
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)
Those seemed to work fine.
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)
This led to this error output: 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")
returnedTRUE
andgetCall(mediatorModel)[[1]]
returnedlme4::lmer
回答1:
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"
.
来源:https://stackoverflow.com/questions/41253257/error-using-mediation-package-with-lme4-model-mediator-model-is-not-yet-impleme