Plotting the moderation effect

208 views
Skip to first unread message

Janez Gorenc

unread,
Jun 30, 2023, 1:27:32 PM6/30/23
to lavaan
Hello, 

I have created a SEM with direct and indirect effects, it works like magic. But now I'd like to plot the moderation effects, like in the picture (which is symbolic):

download.png

The plot in the picture was created by plotMod(), but this only works with lm().

So, my questions:
1. Can I plot the moderation effrect with the fit results begotten from lavaan?
2. If this is not possible,  I would use poltMod(), but the problem is how to transform my regression code into one fit for lm()? Can someone please help? Thank you!

Here is the code:

SEM_model4<-'
          #regressions model
          ZEA4items~b1*ZEC3dim+b2*ZESEsum+b3*ZESExZEC
          ZEA2~c*ZEA4items+a1*ZEC3dim+a2*SPOL+a3*DRUZ_BINAR#+e*ZESEsum
         
          #covariances
          ZEC3dim~~ZESExZEC
          ZEC3dim~~ZESEsum
          ZESEsum~~ZESExZEC

          #variances
          DRUZ_BINAR~~DRUZ_BINAR
          SPOL~~SPOL
          ZEA2~~ZEA2
          ZEC3dim~~ZEC3dim
          ZESEsum~~ZESEsum
          ZEA4items~~ZEA4items
          ZESExZEC~~ZESExZEC
         
          # key
          ## IV - ZEC3dim
          ## Z - ZESExZEC
          ## M - ZEA4items
          ## DV - ZEA2
          ## ESE - ZESEsum
          ## SPOL - SPOL
          ## DRUZ - DRUZ_BIN
         
          #indirect
          indirect_IV_M_DV:=b1*c
          indirect_Z_M_DV:=b3*c
          indirect_ESE_M_DV:=b2*c
          
          #direct
          direct_M_DV:=c
          direct_Z_M:=b3
          direct_IV_M:=b1
          direct_ESE_M:=b2
          direct_IV_DV:=a1
          direct_SPOL_DV:=a2
          direct_DRUZ_DV:=a3
  
          #total
          Total_IV_DV:=b1*c+a1
          Total_Z_DV:=b3*c+0
          '

Christian Arnold

unread,
Jun 30, 2023, 3:46:29 PM6/30/23
to lav...@googlegroups.com
Are there any moderators in your model? If you have four points (that's what the graph looks like), plotly is a strong package.
From: lav...@googlegroups.com <lav...@googlegroups.com> on behalf of Janez Gorenc <janez...@gmail.com>
Sent: Friday, June 30, 2023 7:27:31 PM
To: lavaan <lav...@googlegroups.com>
Subject: Plotting the moderation effect
 
--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/c174b66a-2b2c-416f-85bf-487d356c41a1n%40googlegroups.com.

Janez Gorenc

unread,
Jun 30, 2023, 4:16:01 PM6/30/23
to lav...@googlegroups.com
Does plotly work with lavaan outputs?

Yes, the moderator in my model is ZESExZEC.





--
Janez Gorenc

Christian Arnold

unread,
Jun 30, 2023, 4:25:07 PM6/30/23
to lav...@googlegroups.com
Then you just have to calculate the points to create the diagram with any package, right? What exactly is your problem about?
Sent: Friday, June 30, 2023 10:15:30 PM
To: lav...@googlegroups.com <lav...@googlegroups.com>
Subject: Re: Plotting the moderation effect
 

Shu Fai Cheung (張樹輝)

unread,
Jun 30, 2023, 7:45:37 PM6/30/23
to lavaan
Hi,

You can try the plot-method for the output of cond_indirect_effects() from the manymome package:


Despite the name "cond_indirect_effects", it can also be used for a moderated path without mediators. Just omit the argument "m" for mediator(s).

Actually, the plot method only supports a path without mediators (for now).

The second example in the help page of the plot-method is similar to your case. The model has mediators but the method can still be used on paths not moderated.

Hope this helps.

-- Shu Fai

P.S.: The plot looks similar to that in plotmod() because it was indeed an extension of plotmod() for SEM results.
Reply all
Reply to author
Forward
0 new messages