3

Hi I am new to R and this forum. I have the same problem as a previous poster, but mine was not resolved with the answer. I get the message: "mediator model is not yet implemented" when I try to run a multilevel mediation model using package lme4 and mediation.

My data:

data.frame':    25383 obs. of  115 variables:
$ PID                        : num  1 1 1 1 1 1 1 1 1 1 ...
$ T0_AGE                     : num  66.6 79.7 85.6 87 79.9 67.4 80 72 80.1 
68$ T0_ASEXE                 : Factor w/ 2 levels "Male","Female": 1 1...
$ T0_ALIVING_R               : num  0 0 0 0 1 0 0 0 1 0 ...
$ T0_educationcat            : Factor w/ 3 levels "high","middle",..
$ FI_morbidity_corrected     : num  0.0625 0 0.125 0.0625 0.0625 0.125 ……
$ FI_SRH                     : num  0.5 0.375 0.75 0.625 0.375…."

I am trying to see how FI_morbidity_corrected mediates the relationship between T0_educationcat and FI_SRH. I'm specifying a random intercept for PID (project ID) as data is clustered in different studies/projects. I am controlling for confounders T0_ASEXE + T0_AGE + T0_ALIVING_R

med.fit <- lmer(FI_morbidity_corrected~T0_educationcat + T0_ASEXE + T0_AGE + 
T0_ALIVING_R + (1|PID),data=topicsmds)
out.fit <- lmer(FI_SRH~FI_morbidity_corrected + T0_educationcat + T0_ASEXE + 
T0_AGE + T0_ALIVING_R + (1|PID),data=topicsmds)

This works, but then:

med23.out <- mediate(med.fit, out.fit, treat = "T0_educationcat", mediator = 
"FI_morbidity_corrected", control.value = "high", treat.value = "middle", 
sims = 100)
summary(med23.out)

and

med24.out <- mediate(med.fit, out.fit, treat = "T0_educationcat", mediator = 
"FI_morbidity_corrected", control.value = "high", treat.value = "low", sims 
= 100)
summary(med24.out)

Give me the error:

mediator model is not yet implemented

I have loaded the lme4 pakage using library(lme4) as suggested, but still get this error.

inherits(mediatorModel, "merMod") returned TRUE

getCall(mediatorModel)[[1]] returned lme4::lmer

Thanks!

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
Carmen Franse
  • 31
  • 1
  • 4

1 Answers1

10

Are you loading the package lmerTest? If so, class(med.fit[[1]]) returns merModLmerTest instead of lmerMod - but the mediation package expects the latter. Unloading lmerTest would solve the problem.

Adam Morris
  • 293
  • 3
  • 8
  • +1. Worked for me. Though some people may want to know I had to then re-estimate `med.fit` and `out.fit` (having called `detach_package(lmerTest)`) before again calling `mediate` for it to work. Might save someone a few minutes. – Cole Robertson Sep 02 '19 at 13:49
  • I used the [this](https://stackoverflow.com/questions/6979917/how-to-unload-a-package-without-restarting-r) `detach_package()` function. – Cole Robertson Sep 02 '19 at 13:56