Reputation: 367
I know how to run multiple mediator models in lavaan and multiple group models in lavaan, but I now want to compare mediation parameters across the 2 groups. However, when I define parameters, they are only printed for the first group, so I don't know if they are different for the second group or not. Is there a trick to doing that? I tried to define parameters as I would define path constraints for multigroup, e.g. c(z, z)*var (so, in this case, I tried something like: indirect effect: c((a1*b), (a1*b)), to make it print two outputs, one for each group, but it doesn't work), and I can't find anything on this topic online. Here is an example of a code:
Model <- 'LatentVar =~ c(z, z)*var1 + c(z, z)*var2 + c(z, z)*var3
VarA~ c(a1, a1)*VarB + c(a2, a2)*LatentVar + c(a3, a3)*VarC
VarD ~ c(b, b)*VarA + c(c1, c1)*VarB + c(c2, c2)*LatentVar + c(c3, c3)*VarC
LatentVar ~~ VarA
LatentVar ~~ VarC
indirect_VarA := a1 * b
indirect_LatentVar := a2 * b
indirect_VarC := a3 * b
total_VarA := c1 + (a1 * b)
total_LatentVar := c2 + (a2 * b)
total2_VarC := c3 + (a3 * b)'
fit<- sem(model = Model, data = dat, estimator= "MLR", missing = "FIML", std.lv = T, group = "group")
summary(fit, standardized = TRUE, fit = TRUE, ci = T)
Thank you! Maria
Upvotes: 1
Views: 1270
Reputation: 86
For your purposes, the defined parameters must have unique names for each group and each variable, and must not be reused as you have done. Reworking your code like this should give you the estimates you want for each group:
Model <- 'LatentVar =~ c(z_v1_g1, z_v1_g2)*var1 + c(z_v2_g1, z_v2_g2)*var2 + ...
VarA~ c(a1_g1, a1_g2)*VarB + c(a2_g1, a2_g2)*LatentVar + ...
VarD ~ c(b_g1, b_g2)*VarA + ...
Then for the parameter definitions, you need to specify each path you are interested in, in each group:
indirect_VarA (group 1) := a1_g1 * b_g1
indirect_VarA (group 2) := a1_g2 * b_g2
...
As an aside, reusing parameter names can be a used strategically depending on your model. For example, if you had three groups and wanted to fix the parameters of the first two to be equal for a specific variable, you could write something like
Var1 ~ c(a, a, b)*Var2
This will force lavaan to estimate equivalent parameters for the first two groups, but freely estimate it in the third.
Upvotes: 2