metaSEM_Indirect effects via multiple mediators
 Eva CUI
 Joined: 03/22/2022
                Eva CUI
 Joined: 03/22/2022
    Hello all,
I am intereseted to test the indirect effects with multiple sequential mediators. I am wondering how would it possible to estiamte it? I tried to use the R code below, but there are warnings listed below. It would be highly appreciated if anyone would provide your thoughts? Thank you so much in advance!
R.code
##With direct effect of PS on RC
##definiiton of direct and indirect effects##
#direct <- mxAlgebra(c, name = "direct")
#indirect_Voc <- mxAlgebra(e*b, name = "indirect_Voc")
#indirect_WR <- mxAlgebra(i*a, name = "indirect_WR")
#indirect_PA_WR <- mxAlgebra(j*h*a, name = "indirect_PA_WR")
#indirect_MA_WR <- mxAlgebra(k*g*a, name = "indirect_MA_WR")
#indirect_PA_Voc <- mxAlgebra(j*d*b, name = "indirect_PA_Voc")
#indirect_MA_Voc <- mxAlgebra(k*f*a, name = "indirect_MA_Voc")
SEM13.13 <-
  'RC ~ a*WR + b*Voc + c*PS
  Voc ~ d*PA + e*PS +f*MA
  WR ~ g*MA + h*PA + i*PS
  PA ~ j*PS
  MA ~ k*PS
  PS ~~ 1*PS
  RC ~~ RC
  Voc ~~ WR
  PA ~~ MA'
plot(SEM13.13)
cormatrices13
TS1 <- tssem1(cormatrices13, n, method = "REM")
summary(TS1)
##Pooled correlation matrix
averageR <- vec2symMat(coef(TS1, select = "fixed"), diag = FALSE)
row_names <- varnames13
col_names <- varnames13
rownames(averageR) <- row_names
colnames(averageR) <- col_names
averageR
#Fit the pooled correlation matrix to the model#
RAM13.13 <- lavaan2RAM(SEM13.13, obs.variables = varnames13)
RAM13.13
##definition of direct and indirect effects
direct <- mxAlgebra(c, name = "direct")
indirect_Voc <- mxAlgebra(e*b, name = "indirect_Voc")
indirect_WR <- mxAlgebra(i*a, name = "indirect_WR")
Indirect_PA_WR <- mxAlgebra(j*h*a, name = "indirect_PA_WR")
Indirect_MA_WR <- mxAlgebra(k*g*a, name = "indirect_MA_WR")
Indirect_PA_Voc <- mxAlgebra(j*d*b, name = "indirect_PA_Voc")
Indirect_MA_Voc <- mxAlgebra(k*f*a, name = "indirect_MA_Voc") 
TS2_13.13 <- tssem2(TS1, RAM = RAM13.13, diag.constraints = TRUE,
                    mx.algebras = list(Ind = mxAlgebra(e*b,name = "Ind")))
summary(TS2_13.13)
Results:
 Estimate Std.Error    lbound    ubound
k           0.330281        NA  0.058848  0.477129
j           0.257587        NA  0.178920  0.393154
c           0.082494        NA -0.108852  0.322229
b           0.480529        NA  0.100640  0.595549
a           0.351818        NA  0.093652  0.672354
f           0.420111        NA -0.026672        NA
d           0.042787        NA -0.202462  0.380554
e           0.062226        NA        NA  0.300401
g           0.227029        NA -0.032817        NA
h           0.267327        NA  0.014386  0.436680
i           0.185371        NA        NA  0.317640
MAWITHMA    0.883892        NA  0.883892  0.891657
PAWITHMA    0.247157        NA  0.114809  0.513876
PAWITHPA    0.943245        NA  0.931907  0.943245
RCWITHRC    0.558048        NA  0.472119        NA
VocWITHVoc  0.698494        NA        NA  0.816915
VocWITHWR   0.193708        NA -0.102425  0.281407
WRWITHWR    0.765924        NA        NA        NA
           z value Pr(>|z|)
k               NA       NA
j               NA       NA
c               NA       NA
b               NA       NA
a               NA       NA
f               NA       NA
d               NA       NA
e               NA       NA
g               NA       NA
h               NA       NA
i               NA       NA
MAWITHMA        NA       NA
PAWITHMA        NA       NA
PAWITHPA        NA       NA
RCWITHRC        NA       NA
VocWITHVoc      NA       NA
VocWITHWR       NA       NA
WRWITHWR        NA       NA
mxAlgebras objects (and their 95% likelihood-based CIs):
              lbound   Estimate    ubound
Ind[1,1] -0.05910647 0.02990153 0.1308758
Goodness-of-fit indices:
                                               Value
Sample size                                5511.0000
Chi-square of target model                   45.4138
DF of target model                            2.0000
p value of target model                       0.0000
Number of constraints imposed on "Smatrix"    5.0000
DF manually adjusted                          0.0000
Chi-square of independence model           1732.6199
DF of independence model                     15.0000
RMSEA                                         0.0628
RMSEA lower 95% CI                            0.0477
RMSEA upper 95% CI                            0.0792
SRMR                                          0.0674
TLI                                           0.8104
CFI                                           0.9747
AIC                                          41.4138
BIC                                          28.1848
OpenMx status1: 3 ("0" or "1": The optimization is considered fine.
Other values indicate problems.)
Warning message:
In print.summary.wls(x) :
  OpenMx status1 is neither 0 or 1. You are advised to 'rerun' it again.
It would be highly appreciated if you are wiling to help!!
Thank you so much!!
Best regards,
Eva
I am afraid that I do not
I am afraid that I do not know what you want to achieve. Moreover, it is unclear what's wrong without a reproducible example.
The warning message is "OpenMx status1 is neither 0 or 1. You are advised to 'rerun' it again." Have you rerun the model to see if it improves?
Log in or register to post comments
In reply to I am afraid that I do not by Mike Cheung
Dear Mike,
Dear Mike,
Thank yo so much for your explaination! I am sorry that I did not put my question clear enough. I basically wanted to conduct the statistical test of the multiple indirect effects (multiple). More importantly, if we can examine both toal indirect effects and individual indirect effect?
I am wondering if I can put my code here again?
#Model specification
Model <-
'RC ~ a*WR + b*Voc + c*MA
Voc ~ c*PA + d*PS + e*MA
WR ~ f*MA + g*PA + h*PS
PA ~ i*PS
MA ~ j*PS
PS ~~ 1*PS
RC ~~ RC
Indirect_wr : = h*a
Indirect_voc : = d*b
Indirect_ma : = j*c
Indirect_pa_voc : = i*c*b
Indirect_pa_wr : = i*g*a
Indirect_ma_voc : = j*e*b
Indirect_ma_wr : = j*f*a'
plot(Model)
##Two-stage MASEM
cormatrices13
TS1 <- tssem1(cormatrices13, n, method = "REM")
summary(TS1)
##Pooled correlation matrix
averageR <- vec2symMat(coef(TS1, select = "fixed"), diag = FALSE)
averageR
##Fit the pooled correlation matrix to the model
RAM13.13 <- lavaan2RAM(SEM13.13, obs.variables = varnames13)
RAM13.13
TS2_13.13 <- tssem2(TS1, RAM = RAM13.13, intervals.type = "LB",
diag.constraints = FALSE,
mx.algebras = list(Ind = mxAlgebra(h*a,name = "Ind")))
summary(TS2_13.13)
TS2_13.13 <- tssem2(TS1, RAM = RAM13.13, intervals.type = "LB",
diag.constraints = FALSE,
mx.algebras = list(Ind = mxAlgebra(*a,name = "Ind")))
Thank you again for your help!
Best regards,
Eva
Log in or register to post comments
There are many syntactic
There are many syntactic errors. For example, the following R code is not a valid expression:
mxAlgebra(*a, name = "Ind")
Do you mean?
mxAlgebra(a*b, name = "Ind")
You may refer to the following examples.
https://github.com/mikewlcheung/code-in-articles/blob/master/Cheung%202021c/Supplementary2.md
Log in or register to post comments
Dear Mike,
Dear Mike,
Thank you so much for providing detailed instruction! Sorry to make you confused. I have corrected the typo(a*b). Thanks for pointing it out.
The reason I raise this question is because I am not quite sure whether it is ok to set the diag.constraints = FALSE. And the goodness of the fit was :
Chi-X2 (df = 5) = 115.55, p <.001, CFI = 0.94, NNFI = 0.81, RMSEA = 0.06, SRMR = 0.08.
I am wondering if this model is acceptable? In MASEM, if the criteria is stricter compared with SEM?
Thank you so much for your patience and valuable time!
Best regards,
Eva
Log in or register to post comments