I was wondering whether running in JASP wouldn’t be easier, which generates an R-script which can be attuned then if you wish?
Gert
--
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/72947bbc-8f6d-4b4e-8a4e-8e5b0cba7fefn%40googlegroups.com.
OK; it is so easy sometimes to run starting models, and then move into R when you need to finetune your model.
From: lav...@googlegroups.com <lav...@googlegroups.com> On Behalf Of Sandra King
Sent: donderdag 20 februari 2025 10:31
To: lavaan <lav...@googlegroups.com>
Subject: Re: Help with moderated mediation analysis
I am not familiar with JASP. Additionally, I am using a secured server that does not have JASP installed, and individual installation of applications/programs is not permitted. Thank you for the suggestion.
To view this discussion visit https://groups.google.com/d/msgid/lavaan/86805ce6-508f-48e2-b7dd-0cf63f81fcd7n%40googlegroups.com.
Hello Dr. Christian,
Thank you very much for your assistance with this issue. I followed your suggestion and tested for measurement invariance. The results indicated that the measurement is equivalent across the groups.
#Configural invariance
cfa.Configural <- sem(modmed, data=data_clean, std.lv=T,
group = "provt")
# Metric (weak) invariance
cfa.metric<- sem(modmed, data=data_clean, std.lv=T,
group = "provt",
group.equal = "loadings")
#Scalar (strong) invariance
cfa.scalar <- sem(modmed, data=data_clean, std.lv=T,
group = "provt ",
group.equal = c("loadings","intercepts"))
fitmeasures(cfa.Configural, c("cfi", "tli"))
cfi tli
1 1
fitmeasures(cfa.metric, c("cfi", "tli"))
cfi tli
0.999 0.998
fitmeasures(cfa.scalar, c("cfi", "tli"))
cfi tli
0.999 0.998
Scaled Chi-Squared Difference Test (method = “satorra.bentler.2001”)
lavaan NOTE:
The “Chisq” column contains standard test statistics, not the
robust test that should be reported per model. A robust difference
test is a function of two standard (not robust) statistics.
Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
cfa.Configural 0 4488.3 4565.1 0.0000
cfa.metric 2 4486.6 4554.8 2.2414 1.7396 2 0.4190
cfa.scalar 4 4484.8 4544.5 4.5070 2.2782 2 0.3201
I then went ahead to run the MG-SEM model below for mediation analysis to compare the regression coefficients:
#final analysis
modmediated_lv2 <- "
Ints =~ img1 + img2 + img3
totdp ~ c(a1,a2)*Ints
ART_Adherence ~ Ints + c(b1,b2)*totanx + age
#Defining new parameters
a1b1 := a1 * b1 #Indirect effect for group 1 and group 2
a2b2 := a2 * b2
modmed := a1b1 - a2b2 # Moderated mediation index (I'm not sure if this is correct since my goal is to conduct a moderated mediation analysis and not just the moderation; I assume the moderated moderation difference as to be between the indirect effects.)#
"
#fit the model
final_fit2 <- sem(modmediated_lv2, data_clean, group = "provt",
ordered = "TRT_Ad ",
estimator = "DWLS",
group.equal = "loadings")
Also, the model ran well and demonstrated a good fit. However, there is an issue with the bootstrapping process, as I received an error message when I ran the code below:
MGSEM_boot _fit <- sem(modmediated_lv2, data_clean, group = "provt",
ordered = "TRT_Ad ",
se = "bootstrap", bootstrap = 5000, estimator = "DWLS",
group.equal = "loadings")
verbose = TRUE)
parameterEstimates(MGSEM_boot _fit, boot.ci.type = "bca.simple", standardized = TRUE, ci=TRUE)
...Error in lavaanify(model = FLAT, constraints = constraints, varTable = lavdata@ov, :
lavaan ERROR: wrong number of arguments in modifier (a1,a2) of element totanxscore~inter_latent
In addition: Warning message:
In lav_options_set(opt) :
lavaan WARNING: information will be set to “expected” for estimator = “DWLS”
>
It appears that the issue is with the labeling in the code, which was done to test the moderated mediation. My question is: how do I run the bootstrap for MG-SEM to obtain the bias-corrected confidence intervals to report.
Thank you once again for your incredible help!
Best,
Sandra
Hi Sandra,
depending on your objective, you can also insert "moderator.a := a2 - a1" and/or moderator.b := b2 - b1". About the problem with the bootstrap: To be honest, I don't immediately see where the problem lies (maybe someone else will notice it?). However, there are a few facets that seem strange to me: (1) Your DV is “ART_Adherence” according to the model specification, but you pass the argument ordered = “TRT_Ad ”. I can't find "TRT_Ad" in the syntax. The error message refers to “totanxscore~inter_latent”. I can't find that in your syntax either. There I only find “totdp ~ c(a1,a2)*Ints”. Something seems strange here. In the very first step, I would look at what R has actually stored in the "modmediated_lv2" object: cat(modmediated_lv2).
HTH
Christian
Hi Dr. Christian,
I apologize for the mistake in the code from my previous message. I was typing quickly and didn't notice that. The code was entered correctly in R, as shown below, and that produced the error message. As for the moderation, the "moderator.a := a2 - a1" aligns better with my objective because it reflects the path that is being moderated. Thanks for the suggestion.
The issue I'm facing is with the bootstrapping, which fails to run due to labeling (i.e., c(a1, a2), c(b1, b2)) needed to obtain the path coefficient for each group. When I remove the label or include only a single label (either a1/b1 or a2/b2), the code runs without errors; however, the result is the overall regression coefficient estimate instead of getting separate estimates for Group 1 and Group 2.
Is there any way to obtain the bootstrap estimates and confidence intervals for each group while also being able to estimate the moderated mediation index?
Thank you!
#Analysis code
modmediated_lv2 <- "
inter_latent =~ img1 + img2 + img3
totanxscore ~ c(a1,a2)*inter_latent
TRT_Ad ~ inter_latent + c(b1,b2)* totanxscore + age
#Defining new parameters
a1b1 := a1 * b1 #Indirect effect for group 1 and group 2
a2b2 := a2 * b2
modmed := a2 - a1 # Moderated mediation index
"
MGSEM_boot _fit <- sem(modmediated_lv2, data_clean, group = "provt",
ordered = "TRT_Ad ",
se = "bootstrap", bootstrap = 5000, estimator = "DWLS",
group.equal = "loadings")
verbose = TRUE)
...Error in lavaanify(model = FLAT, constraints = constraints, varTable = lavdata@ov, :
lavaan ERROR: wrong number of arguments in modifier (a1,a2) of element totanxscore~inter_latent
In addition: Warning message:
In lav_options_set(opt) :
lavaan WARNING: information will be set to “expected” for estimator = “DWLS”
MGSEM_boot _fit <- sem(modmediated_lv2, data_clean, group = "provt",
ordered = "TRT_Ad ",
se = "bootstrap", bootstrap = 5000, estimator = "DWLS",
group.equal = "loadings")
verbose = TRUE)
To view this discussion visit https://groups.google.com/d/msgid/lavaan/8520ac75-3557-4f10-85eb-03e3a7c31bc6n%40googlegroups.com.