Plotting interactions in path analysis

256 views
Skip to first unread message

모르모트군

unread,
Jul 8, 2022, 8:22:54 AM7/8/22
to lavaan

Hello,

I am trying to plot the interaction term in my path model.
My model:

path1 <-
  'var1 ~ A*zindex+E*zah+
c1*zage+c2*zsex+ c3*zedu+c31*zincome+
c32*var2
DV~ I*var1:var2+
F*var1+G*var2+
c4*zage+c5*zsex+c6*zedu+c9*zincome+c10*zindex'

fit1 <-lavaan::sem(path1, data=mydata, estimator="ml")


I would like to plot the term (var1:var2), like the attached figure, to see the details.
(The figure is not generated by me; it is just an example that I downloaded on google).

Note that intProd() or probe2WayMC() will not work here, since I am conducting interactions among observed variables, not latent variables.

Thank you,

download.png

Terrence Jorgensen

unread,
Aug 24, 2022, 7:16:09 AM8/24/22
to lavaan
intProd() or probe2WayMC() will not work here, since I am conducting interactions among observed variables, not latent variables.

One way to hack this would be to treat each observed variable (including the product term, but you should add that as a variable in your data) as single-indicator factors.  Then you should be able to use semTools::plotProbe() 

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

Kevin Teoh

unread,
Dec 7, 2022, 8:58:24 AM12/7/22
to lavaan
Dear Dr Jorgensen, Dear Community, 

I too am trying add an interaction term to a path model, and am trying to work with this hack of treating the IV, DV, Moderator, and Interaction variables as single indicator factors. However, probe2WayMC is bringing up "Error in varEst[targetcol, targetcol] : subscript out of bounds". 

Would anyone have any advise on what I might have missed? I have also tried a basic model without any additional variables/controls; where all the variables are latent factors with a single observed item; and where all variables are observed variables. I get pretty much the same model fit and estimates. 

Any help with the error message is appreciated. I have added script below. 

Thank you

Kevin

# Model estimation with latent interaction

int_model <- '
#loadings
iv =~ IVc
mod =~ MODc
int =~ ICMODdc #doublecentered
dv =~ DV

#regression
mod ~ CTRL1 + CNTRL2 + CNTRL3 + VAR1 + VAR2
dv ~ iv + mod + int + CTRL1 + CNTRL2 + CNTRL3 + VAR3 + VAR4

#covariances
VAR3 ~~ iv + mod + VAR4
VAR4 ~~ iv + mod

'

int_fit <- sem(int_model, data = data, estimator="MLM")
summary(int_fit, fit.measures = TRUE, standardized=TRUE)

# Simple Slopes
probe <- probe2WayMC(int_fit, c("iv", "mod", "int"), "dv", "mod",
c(-sqrt(0.459),0, sqrt(0.459))) #estimators from moderator
probe

plotProbe(probe, c(-3,3))


Terrence Jorgensen

unread,
Dec 12, 2022, 7:04:47 AM12/12/22
to lavaan
"Error in varEst[targetcol, targetcol] : subscript out of bounds". 

I recognize that from a while ago, probably fixed already.  Does this happen with the latest development version?


Terrence D. Jorgensen    (he, him, his)

Reply all
Reply to author
Forward
0 new messages