Problem probing a two-way interaction among observed variables from a Lavaan fit object

547 views
Skip to first unread message

Michael Carter

unread,
Jul 29, 2019, 4:10:44 PM7/29/19
to lavaan
To the Lavaan Community, 

I am currently in the process of writing up an SEM analysis which includes multiple two-way interactions between observed variables in Lavaan. To my knowledge, the only means of probing two-way interactions in R using premade functions include probe_interaction(), probemod(), probe2wayRC(), and probe2wayMC(). However, these functions (i.e., the first two) do not work on lavaan fit objects, and the latter two only appears to probe interactions among latent variables in Lavaan. 



I want to implement the Johnson-Neyman Technique to test two-way interactions among observed variables from a Lavaan fit object and I would greatly appreciate any help in this matter. I have been unable to identify a post on this Google forum or elsewhere which addresses this issue. I am willing to work with others to code up a solution. 

I know that Preacher provides a nice set of plug and play tools to probe interactions on his website (http://www.quantpsy.org/). However, I would prefer to conduct the analysis in R as it would (1) mitigate the potential for error and (2) make this type of analysis easier. I assume that others would appreciate this as well and that such a function would benefit the R community longterm. 

Thank you for taking the time to read this post. I look forward to and welcome any and all replies. 

- Michael 


Mauricio Garnier-Villarreal

unread,
Jul 30, 2019, 3:11:52 PM7/30/19
to lavaan

Michael

The probe_interaction and probmod are design to work with other types of R models, not lavaan models. the probe2way functions are designed to work with lavaan, so these are the ones that will automatically integrate lavaan

You can do a probe with lavaan and measured variables, like this

### use the ":" operator to do an in code interaction
mod4 <- '
dep ~ socsup + stress + socsup:stress
'
fit_int4 <- cfa(mod4, data=dat2, meanstructure=T,fixed.x=F)
summary(fit_int4, standardize=T, rsquare=T)


## test simple slopes
values_probe1 <- c(mean(dat2$socsup) - sd(dat2$socsup),
                   mean(dat2$socsup),
                   mean(dat2$socsup) + sd(dat2$socsup))
 
result2way2 <- probe2WayMC(fit_int4, nameX=c("socsup","stress","socsup:stress"),
                          nameY="dep", modVar="socsup", valProbe=round(values_probe1,3) )
result2way2
plotProbe(result2way2, xlim = c(min(dat2$stress),max(dat2$stress)),
          xlab="Stress",ylab="Depression")


## continuous values to probe
## Johnson-Neyman, can specify any range of values to probe at and identify the regions
sort(dat2$socsup)

values_probe2 <- seq(from=min(dat2$socsup), to=max(dat2$socsup), by=1) ### here you can set other possible values if you want

result2way3 <- probe2WayMC(fit_int4, nameX=c("socsup","stress","socsup:stress"),
                           nameY="dep", modVar="socsup", valProbe=values_probe2)
result2way3
plotProbe(result2way3, xlim = c(min(dat2$stress),max(dat2$stress)),
          xlab="Stress",ylab="Depression", legendArgs=list(x="topleft")) ### can also set legend=FALSE, so it doesnt print any legend in the plot


hope this helps

Michael Carter

unread,
Jul 31, 2019, 4:25:35 PM7/31/19
to lavaan

Thank you for your comment, Mauricio! Your example was very helpful. 
 
Hopefully, the R documentation for probe2WayMC() will update to make its applicaitons clearer (i.e., to probe observed interacitons as well). 
     
       - Michael  

Anne Olsen

unread,
Dec 26, 2021, 8:30:55 AM12/26/21
to lavaan
Hi,

I have already posted my question, but I cannot see it (anyway sorry in advance for double posting).

I have a below model, with predictor being observed and outcome latent variable and I would like to do single slopes analysis. I followed the code in this thread; however, I get the following error:  “Error in varEst[targetcol, targetcol] : subscript out of bounds”. I read this is error due paths from the predictors to the outcome using a label, yet I do not have labels – so not sure how to solve it.

Thanks!

Best,

Anne

 

model_sem <- HYGG =~ hyg_1 + hyg_2 + hyg_3 +  hyg_4 + hyg_5 + hyg_6

              HYGG ~ pos_emo_country + trustgov + pos_emo_country:

hyg_2 ~~ hyg_3'

 

model_sem.fit <- cfa(model_sem,data = mydata, missing="fiml.x",fixed.x=F)

summary(model_sem.fit, fit.measures = TRUE, standardized=T,rsquare=T)

 

values_probe1 <- c(mean(mydata$trustgov) - sd(mydata$trustgov),
                   mean(mydata$trustgov),
                   mean(mydata$trustgov) + sd(mydata$trustgov))

result2way2 <- probe2WayMC(model_sem.fit, nameX=c("trustgov","pos_emo_country","pos_emo_country:trustgov"),
                           nameY="HYGG", modVar="trustgov", valProbe=round(values_probe1,3) )
result2way2

Terrence Jorgensen

unread,
Jan 2, 2022, 9:15:32 PM1/2/22
to lavaan
probe2WayMC() and related functions are only designed to probe latent interactions.  Your predictors are observed, so you can simply center the moderator at the levels of interest and fit your model again to obtain those simple slopes.  Or you could use this online calculator:


The fact that the outcome is latent is irrelevant.

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

Reply all
Reply to author
Forward
0 new messages