Moderated mediation on b path only using "mediation" package

Viewed 60

based on this wonderful post, I am trying to run my own moderated mediation, but my model has a dichotomous moderator only on b path.

The code goes like this:

library(mediation)

Model.m<-lm(mpg ~ drat, data = mtcars)

Model.y<-lm(disp ~ mpg*vs + drat, data = mtcars)

Mod.Med.vs1 <- mediate(model.m = Model.m, model.y =  Model.y,    
                       covariates = list(vs = 1),
                       boot = TRUE,   
                       boot.ci.type = "bca", sims = 2000, mediator="mpg", treat="drat")

# Here I get the error

Mod.Med.vs0 <- mediate(model.m = Model.m, model.y =  Model.y,    
                       covariates = list(vs = 0),
                       boot = TRUE,   
                       boot.ci.type = "bca", sims = 2000, mediator="mpg", treat="drat")

Mod.Med     <- mediate(model.m = Model.m, model.y =  Model.y,    
                  boot = TRUE,   
                  boot.ci.type = "bca", sims = 2000, mediator="mpg", treat="drat")

I get an error right after running Mod.Med.vs1:

Error in `[.data.frame`(pred.data.t, , vl) : undefined columns selected

Importantly, if I multiply drat with vs also in Model.m it works fine, but again, I am not interested in investigating the influence of the moderator prior to the mediator.

Any suggestions?

0 Answers
Related