Using a binary moderator in path analysis

60 views
Skip to first unread message

blairmid

unread,
Mar 28, 2025, 7:50:30 PM3/28/25
to lavaan
Hi lavaan group,

I am trying to test a moderated mediation model that utilizes multilevel data (individuals in teams) and has a binary categorical moderator coded as 0 or 1. I am specifically interested in finding the indirect and direct effect sizes.

In other mediation models I've tested, I've used the average of the moderator +/- 1 SD to get the high and the low values, but with this model, the moderator is binary (0/1). To calculate the effect sizes, am I able to directly use a 0 or 1 in my calculations (see picture below) or do I need to use a different approach?

Here is an image of the model:
Model image.png

And the code I am currently using, where 0 and 1 have been plugged in directly for calculating effect sizes:
Path model code lavaan.png

Thank you for your help!



Here is the code as text for reference:
path_model_1 <- '

Mediator_T2 ~ a1*IV + a2*Moderator + a3*IV:Moderator
DV ~ c1*IV + c2*Moderator + c3*IV:Moderator + b*Mediator

indirect.effect.mod_equals_0 :=(a1+a3*0)*(b)
indirect.effect.mod_equals_1 :=(a1+a3*1)*(b)
indirect.effect.difference := indirect.effect.mod_equals_0 - indirect.effect.mod_equals_1

direct.effect.mod_equals_0 :=c1+c3*0
direct.effect.mod_equals_1 :=c1+c3*1
direct.effect.difference := direct.effect.mod_equals_0 - direct.effect.mod_equals_1

total.effect.mod_equals_0 := direct.effect.mod_equals_0 + indirect.effect.mod_equals_0
total.effect.mod_equals_1 := direct.effect.mod_equals_1 + indirect.effect.mod_equals_1
total.effect.difference := total.effect.mod_equals_0 - total.effect.mod_equals_1

'

fit_path_model_1 <- sem(model = path_model_1, data = path_model_data_1, 
                        cluster = "Team_assignment", bootstrap = 5000)
summary(fit_path_model_1, fit.measures = TRUE)

Terrence Jorgensen

unread,
Apr 1, 2025, 4:47:15 AM4/1/25
to lavaan
am I able to directly use a 0 or 1 in my calculations

Did you try it before posting here?  And does your output match your manual calculations?

FYI, some of your defined variables are more simply defined:
 
indirect.effect.difference := indirect.effect.mod_equals_0 - indirect.effect.mod_equals_1

That is simply a3*b

direct.effect.difference := direct.effect.mod_equals_0 - direct.effect.mod_equals_1

That is simply c3, already an estimated parameter.
 
Terrence D. Jorgensen    (he, him, his)
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam
http://www.uva.nl/profile/t.d.jorgensen

Reply all
Reply to author
Forward
0 new messages