6
$\begingroup$

The well-known PROCESSr package unfortunately does not support serial mediation in r, as shown by the model below. I have been looking all over the net, but couldn't find a package that would allow me to specify the below model in r.

How would you go about setting up a model like this one in r? Is there a package to do so?

serial mediation

$\endgroup$

1 Answer 1

9
$\begingroup$

This should probably be migrated to StackOverflow since it is about software, but:

You could do this in the R package lavaan. In your model, you would first specify models for M1, M2, and Y. We will want to label all the paths, as well. I will label c' as cp, for "c-prime":

M1 ~ a1 * X
M2 ~ a2 * X + d21 * M1
Y ~  cp * X + b1  * M1 + b2 * M2

The indirect effect, ind_eff is then defined, per Hayes, as a1 * d21 * b2:

ind_eff := a1 * d21 * b2

You need to put this all in a string object:

model <- "
  M1 ~ a1 * X
  M2 ~ a2 * X + d21 * M1
  Y ~  cp * X + b1  * M1 + b2 * M2
  ind_eff := a1 * d21 * b2
"

Then you just run the model using bootstrapped confidence intervals to get the confidence interval for the indirect effect (ind_eff):

fit <- lavaan::sem(model = model, data = dat, se = "boot", bootstrap = 5000)

Where dat is the name of your data frame and 5000 is the number of bootstrap resamples you would like to do (this will likely take a few minutes).

To look at your results, you can call:

lavaan::parameterEstimates(fit, boot.ci.type = "bca.simple")
$\endgroup$
10
  • $\begingroup$ Thank you Mark. Are there any requirements regarding the variables? In my case variable X is a factor with 3 levels, the other variables are all continous. $\endgroup$
    – Jens Stach
    Commented Apr 23, 2018 at 15:18
  • $\begingroup$ This will assume that your mediators and dependent variable are conditionally normally distributed (per usual). lavaan, unless they updated it, requires all variables to be numeric. I would recommend turning the X variable into two binary variables (level 1 vs. level 2; level 1 vs. level 3, for example). $\endgroup$
    – Mark White
    Commented Apr 23, 2018 at 15:24
  • $\begingroup$ due to my hypothesis, it makes sense to combine level1 and 2 to one level and keep level3 the way it is. Thus the number of cases between the final two levels would be quite different. Is that a problem? $\endgroup$
    – Jens Stach
    Commented Apr 23, 2018 at 15:39
  • $\begingroup$ That works! Just combine two of them into the same level and make it a numeric 0 or 1 variable $\endgroup$
    – Mark White
    Commented Apr 23, 2018 at 15:40
  • $\begingroup$ pathcoefficients a2,d21,b1 and b2 all come out significant, yet a1 and cp do not. In particular since there is no significance of a1, it seems that mediation does not take place the way I hypothesized, otherwise, a1 would have also been significant. Would you agree with this Mark? $\endgroup$
    – Jens Stach
    Commented Apr 23, 2018 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.