1

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:

  1. inherits(mediatorModel, "merMod") returned TRUE and
  2. getCall(mediatorModel)[[1]] returned lme4::lmer
Joshua Rosenberg
  • 4,014
  • 9
  • 34
  • 73
  • 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"`. – Weihuang Wong Dec 21 '16 at 00:55
  • If this suggestion doesn't work, please include some sample data that allows us to reproduce your problem. – Weihuang Wong Dec 21 '16 at 01:02
  • That did the trick. Chaned to `library(lme4)`, then just call `lmer`. Thank you. – Joshua Rosenberg Dec 21 '16 at 01:06
  • 1
    Great. I've copied my comment as an answer so that we can close this out. – Weihuang Wong Dec 21 '16 at 01:11

1 Answers1

3

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".

Weihuang Wong
  • 12,868
  • 2
  • 27
  • 48