Moderation and mediation PROCESS in lavaan

731 views
Skip to first unread message

Danilo Assis Pereira

unread,
Apr 22, 2016, 4:25:01 PM4/22/16
to lavaan
Hi, I tried to use mplus2lavaan() function in the following syntax, but without success. I would like to use some codes from http://offbeat.group.shef.ac.uk/FIO/model2.htm in lavaan package. Could someone help me with this?

Thanks,

Danilo A Pereira 
Brazilian Psychometrician

=============
Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examples

Model 2: 2 moderators, 2-way interactions with predictor only
Example Variables: 1 predictor X, 2 moderators W, Z, 1 outcome Y

Model Equation(s):
Y = b0 + b1X + b2W + + b3Z + b4XW + b5XZ

Algebra to calculate indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1X + b2W + b3Z + b4XW + b5XZ

Hence... grouping terms into form Y = a + bX
Y = (b0 + b2W + b3Z) + (b1 + b4W + b5Z)X

Hence...
One direct effect of X on Y, conditional on W and Z:
b1 + b4W + b5Z

Mplus code for the model:

! Predictor variable - X 
! Moderator variable(s) - W, Z 
! Outcome variable - Y

USEVARIABLES = X W Y XW XZ;

! Create interaction terms 
! Note as new vars they have to be placed at end of USEVARIABLES subcommand above

DEFINE: 
   XW = X*W; 
   XZ = X*Z;

ANALYSIS: 
   TYPE = GENERAL; 
   ESTIMATOR = ML; 
   BOOTSTRAP = 10000;

! In model statement name each path, and intercept, using parentheses

MODEL: 
   [Y] (b0); 
   Y ON X (b1); 
   Y ON W (b2); 
   Y ON Z (b3); 
   Y ON XW (b4); 
   Y ON XZ (b5);

! Use model constraint subcommand to test simple slopes 
! You need to pick low, medium and high moderator values for both W and Z, 
! for example, of 1 SD below mean, mean, 1 SD above mean

! 2 moderators, 3 values for each, gives 9 combinations 
! arbitrary naming convention for simple slopes used below: 
! MEW_LOZ = medium value of W and low value of Z, etc.

MODEL CONSTRAINT: 
   NEW(LOW_W MED_W HIGH_W LOW_Z MED_Z HIGH_Z LOW_LOZ MEW_LOZ HIW_LOZ 
   LOW_MEZ MEW_MEZ HIW_MEZ LOW_HIZ MEW_HIZ HIW_HIZ);

   LOW_W = #LOWW;   ! replace #LOWW in the code with your chosen low value of W 
   MED_W = #MEDW;   ! replace #MEDW in the code with your chosen medium value of W 
   HIGH_W = #HIGHW;   ! replace #HIGHW in the code with your chosen high value of W

   LOW_Z = #LOWZ;   ! replace #LOWZ in the code with your chosen low value of Z 
   MED_Z = #MEDZ;   ! replace #MEDZ in the code with your chosen medium value of Z 
   HIGH_Z = #HIGHZ;   ! replace #HIGHZ in the code with your chosen high value of Z

! Now calc simple slopes for each value of W and Z

   LOW_LOZ = b1 + b4*LOW_W + b5*LOW_Z; 
   MEW_LOZ = b1 + b4*MED_W + b5*LOW_Z; 
   HIW_LOZ = b1 + b4*HIGH_W + b5*LOW_Z;

   LOW_MEZ = b1 + b4*LOW_W + b5*MED_Z; 
   MEW_MEZ = b1 + b4*MED_W + b5*MED_Z; 
   HIW_MEZ = b1 + b4*HIGH_W + b5*MED_Z;

   LOW_HIZ = b1 + b4*LOW_W + b5*HIGH_Z; 
   MEW_HIZ = b1 + b4*MED_W + b5*HIGH_Z; 
   HIW_HIZ = b1 + b4*HIGH_W + b5*HIGH_Z;

! Use loop plot to plot model for all combinations of low, med, high values of W and Z 
! NOTE - values of 1,5 in LOOP() statement need to be replaced by 
! logical min and max limits of predictor X used in analysis

   PLOT(PLOW_LOZ PMEW_LOZ PHIW_LOZ PLOW_MEZ PMEW_MEZ PHIW_MEZ 
   PLOW_HIZ PMEW_HIZ PHIW_HIZ);

   LOOP(XVAL,1,5,0.1);

   PLOW_LOZ = (b0 + b2*LOW_W + b3*LOW_Z) + LOW_LOZ*XVAL; 
   PMEW_LOZ = (b0 + b2*MED_W + b3*LOW_Z) + MEW_LOZ*XVAL; 
   PHIW_LOZ = (b0 + b2*HIGH_W + b3*LOW_Z) + HIW_LOZ*XVAL;

   PLOW_MEZ = (b0 + b2*LOW_W + b3*MED_Z) + LOW_MEZ*XVAL; 
   PMEW_MEZ = (b0 + b2*MED_W + b3*MED_Z) + MEW_MEZ*XVAL; 
   PHIW_MEZ = (b0 + b2*HIGH_W + b3*MED_Z) + HIW_MEZ*XVAL;

   PLOW_HIZ = (b0 + b2*LOW_W + b3*HIGH_Z) + LOW_HIZ*XVAL; 
   PMEW_HIZ = (b0 + b2*MED_W + b3*HIGH_Z) + MEW_HIZ*XVAL; 
   PHIW_HIZ = (b0 + b2*HIGH_W + b3*HIGH_Z) + HIW_HIZ*XVAL;

PLOT: 
   TYPE = plot2;

OUTPUT: 
   STAND CINT(bcbootstrap);

To cite this page and/or any code used, please use: 
Stride, C.B., Gardner, S., Catley, N. & Thomas, F.(2015) 'Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examples', http://www.offbeat.group.shef.ac.uk/FIO/mplusmedmod.htm



Terrence Jorgensen

unread,
Apr 23, 2016, 6:32:55 AM4/23/16
to lavaan
Hi, I tried to use mplus2lavaan() function in the following syntax, but without success.

Have you looked at the lavaan tutorial to learn lavaan's syntax rules?  They are very similar to Mplus (e.g., replace "ON" with "~"). Here is one of the tutorial pages that explains how to create user-defined parameters as functions of other parameters (use the ":=" operator instead of just  "=" in Mplus):  http://lavaan.ugent.be/tutorial/mediation.html

Here is a previous post with an example of a very similar problem, except calculating simple indirect effects instead of simple direct effects (i.e., simple slopes):  https://groups.google.com/d/msg/lavaan/RW_3TMARGhY/UF9-MBk-GKIJ

I think the reason the mplus2lavaan() function might not work in this situation is that there is no lavaan analog of Mplus's LOOP function, so perhaps you could try it without the LOOP and PLOT parts of the Mplus syntax.  Once you have your parameter estimates, you can save them as R objects called b0, b1, b2, etc. and just use regular R syntax to create the plot.

Terrence D. Jorgensen
Postdoctoral Researcher, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages