Specifying Mediation in SimSem using the Lavaan Syntax

48 views
Skip to first unread message

Kyle Hickerson

unread,
Nov 16, 2025, 4:25:44 AMNov 16
to lavaan
Hello,

I have been working on a large ri-clpm simsem simulation involving indirect effects. Everything runs fine, and the power, bias and coverage estimates existed before adding the indirect effects component. When I added the estimates of the indirect effects, no power, bias or coverage results are exported. I am assuming I am notating it incorrectly in the population model, but is there any way to get those estimates for the indirect effects? I have included an online example that mimics the issue below. Apologies in advance if I have missed something obvious in this process. I know it is possible to conduct mediation in SimSem using the matrix style but I would prefer if at all possible to get those estimates using my existing lavaan syntax. 

- Kyle

simModel <- "

M ~ 0.5*X
Y ~ 0.5*M + 0.5*X

X ~~ 1*X
M ~~ 0.5*M
Y ~~ 0.5*Y
"

fitModel <- "

M ~ a*X
Y ~ b*M + X

M ~~ M
Y ~~ Y

i := a* b
"

simOutput_1 <- sim(
  nRep = 100,
  model = fitModel,
  n = 50, generate = simModel,
  lavaanfun = "lavaan",
  se = "standard"
)
summary(simOutput_1)

Sunthud Pornprasertmanit

unread,
Nov 23, 2025, 1:11:15 AMNov 23
to lav...@googlegroups.com
Hi Kyle,

I fixed two things. First, I label a and b in the simModel. Second, I add i in the simModel and change it to the correct value later.

simModel <- "

M ~ 0.5*X + a*X
Y ~ 0.5*M + 0.5*X + b*M


X ~~ 1*X
M ~~ 0.5*M
Y ~~ 0.5*Y

i := 0.5*0.5 # The paramvalue in the sim function is remembered as 0. Need to fix later

"

fitModel <- "

M ~ a*X
Y ~ b*M + X

M ~~ M
Y ~~ Y

i := a* b
"

simOutput_1 <- sim(
  nRep = 100,
  model = fitModel,
  n = 50, generate = simModel,
  lavaanfun = "lavaan",
  se = "standard"
)

simOutput_1@paramValue[,"i"] <- 0.25 # Fix the wrong i parameter
summary(simOutput_1)

--
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 visit https://groups.google.com/d/msgid/lavaan/f5e69db2-745b-4d26-bf35-38cc195b5085n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages