How to generate A matrice and S matrice for the second stage of TSSEM?
Hi Milke and all,
I'm trying to run a TSSEM to examine the mediation effect for a meta-analysis. However, I'm not sure what's the appropriate way to create the A matrice and S matrice needed for stage 2. Would you please advise?
On your Cheung & Cheung 2014 paper, I saw that the A matrice and S matrice were created manually by typing in the code. Each correlation coefficient was listed in the code. Please see below for an example taken from the supplementary info of that paper. In your introduction of the metaSEM package (see the link below), you have first specified the model via the RAM formulation, you then used lavaan to generate the A and S matrices.
May I know whether I can use the second method to generate the matrices (by specifying a model first)? If not, would you please explain how can I determine 1) the value in weighting the correlation coefficient in the first method and 2) the correct order for the 0 and the weighted correlation coefficient? E.g., If I used the terms incorrectly, I was talking about the 0.2 in the "0.2*b","0.2*c" below.
Thank you for your time and help in advance!
Best wishes,
Iana
Example from Cheung & Cheung 2014 paper:
A1 <- create.mxMatrix(c(0,"0.2*b","0.2*c",
0,0,"0.2*a",
0,0,0),
type="Full", ncol=3, nrow=3, as.mxMatrix=FALSE, byrow=TRUE)
dimnames(A1) <- list(c("LS","JS","JA"), c("LS","JS","JA"))
Example from the introduction of the metaSEM package:
#### Prepare models for stage 2 analysis
model2 <- "## Math is modeled by Spatial and Verbal
Math ~ Spatial2Math*Spatial + Verbal2Math*Verbal
## Variances of predictors are fixed at 1
Spatial ~~ 1*Spatial
Verbal ~~ 1*Verbal
## Correlation between the predictors
Spatial ~~ SpatialCorVerbal*Verbal
## Error variance
Math ~~ ErrorVarMath*Math"
RAM2 <- lavaan2RAM(model2)
Cheung, M.W.-L., and Cheung, S.-F. (2014). Random effects models for meta-analytic structural equation modeling: Review, issues, and illustrations. Manuscript submitted for publication.
Introduction of the metaSEM package
https://cran.r-project.org/web/packages/metaSEM/vignettes/Examples.html…
Dear Iana,
Yes, both methods work. You may specify a model in lavaan syntax and convert it to the RAM specification. Alternatively, you may specify the model in RAM. The supplementary material of the following paper explains the RAM specification.
https://www.frontiersin.org/article/10.3389/fpsyg.2014.01521
Mike
Log in or register to post comments
In reply to Dear Iana, by Mike Cheung
Hi Mike,
Hi Mike,
Thank you so much for your response. Thank you for referring me to the supplementary material as well. If I read the supplementary material correctly, I think it did not contain the R codes for the lavaan syntax and conversion to the RAM specification? But I saw that it does some explanation about the RAM specification.
Because I would have to derive the R codes from separate papers of yours, would you mind checking if the R codes below are correct for a meta-analysis of a single mediator? The purpose of the R codes below is to generate the A and S matrices for the second stage of TSSEM, using the second method I mentioned in my first post.
## specifying the model with one mediator: x -> m -> y
model1 <- "y ~ c*x + b*m
m ~ a*x
# Define indirect and direct effects
Indirect := a*b
Direct := c"
## convert the model into RAM lanaguage
RAM <- lavaan2RAM(model1, obs.variables = c("x", "m", "y")))
## generate the A & S matrices
A <- RAM$A
S <- RAM$S
Thank you for your help in advance!
Best wishes,
Iana
Log in or register to post comments
Dear Iana,
You may refer to the following example:
https://github.com/mikewlcheung/code-in-articles/tree/master/Schutte%20Keng%20and%20Cheung%202021
Mike
Log in or register to post comments
In reply to Dear Iana, by Mike Cheung
Thank you so much Mike for
Thank you again for your prompt response and advice :)
Best wishes,
Iana
Log in or register to post comments
Hi Mike,
Hi Mike,
Sorry to bother you again. May I please ask you three more questions?
1) To create a correlation matrix for stage 2 TSSEM, I used the vec2sm function. However, would you please advise how I should determine the order for inputting the figures in the [] brackets (please see an extract below)? Figures 1, 2, and 3 represent an independent variable, a mediator, and a dependent variable respectively.
Matrix_UnadjES <- vec2sm(vec = c(1,Step1$b[1],Step1$b[2],
1,Step1$b[3],
1),
diag = TRUE)
2) In the TTSEM I just run, the p values are shown as NA. Please see an extract below. Am I correct to interpret that the a, b, and c paths are significant because the confidence intervals do not contain a zero? The NA of p values just means there are too many zeros to be shown?
95% confidence intervals: Likelihood-based statistic
Coefficients:
Estimate Std.Error lbound ubound z value Pr(>|z|)
a 0.424924 NA 0.353370 0.496476 NA NA
c 0.143367 NA 0.073578 0.214426 NA NA
b 0.124820 NA 0.055110 0.195717 NA NA
3) I've used your R codes provided in Schutte Keng and Cheung 2021 (from your last post) to generate the results above. But I'm not sure why the a, b, and c paths are not showing in the same order as your paper. I wonder if there's anything wrong with the code?
Thank you for your help in advance.
Best wishes,
Iana
Log in or register to post comments
Hi Iana,
1) I don't know why you need to create a correlation matrix for stage 2 analysis manually. Can you just run tssem2(stage1, ...), where stage1 is the object of stage 1 analysis?
2) Yes, you may check the 95% likelihood-based CI and see if they include 0.
3) I am not aware of this. But I don't think it is a concern as long as your model is correct.
Mike
Log in or register to post comments
In reply to Hi Iana, by Mike Cheung
Hi Mike,
Thank you for your responses!
For 1), I had to create a correlation matrix manually because the studies included in my meta-analysis have dependent effect sizes. I'm following Wilson et al 2016 to tackle this problem.
Would you happen to know how should the order of correlation coefficient be determined when we manually a correlation matrix using the vec2sm function? Or would you please direct me to some relevant materials?
I've tried to search for this information online but I'm afraid there's little information regarding the manual creation of a correlation matrix using the vec2sm function...
Thank you for your help again!
Best wishes,
Iana
Log in or register to post comments
Hi Iana,
Since vec2m is not in the metaSEM package, I have no idea where you get it.
The metaSEM package provides vec2symMat to convert a vector to a symmetric matrix using the column-major. The document provides examples of how to use it.
Best,
Mike
Log in or register to post comments
In reply to Hi Iana, by Mike Cheung
Oh thank you for directing me
Best wishes,
Iana
Log in or register to post comments
In reply to Oh thank you for directing me by iana
Hi Mike,
Sorry to bother you again.
I'm running a TSSEM using R for my meta-analysis. In the second stage of the analysis, I got an error message saying that 'Error in is.pd(aCov) : argument "aCov" is missing, with no default'. However, in your document introducing the metaSEM package (see the link below), there wasn't an argument called "aCov". There was only one called "asyCov". However, on your other document showing the examples of the metaSEM package (see the link below), there was an argument called "aCov", but there wasn't one called "asyCov".
Since the argument "aCov" works in my R, whereas "asyCov" doesn't, would you please confirm that aCov is the correct argument for an asymptotic variance-covariance matrix?
Thank you for your time and help in advance!
Best wishes,
Iana
Your document introducing the metaSEM package:
Supplementary Material: metaSEM: An R Package for Meta-Analysis using Structural Equation Modeling
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4283449/bin/Presentation1.PDF
# wls(Cov = pooledS, asyCov = asyCov....)
The metaSEM package: Examples
https://cran.r-project.org/web/packages/metaSEM/vignettes/Examples.html
# wls(Cov = coef.tssem1FEM(tssem1.obj), aCov = vcov.tssem1FEM(tssem1.obj)...)
Log in or register to post comments
Some names of the arguments
Log in or register to post comments
I see! Thank you Mike for
Best wishes,
Iana
Log in or register to post comments
In reply to I see! Thank you Mike for by iana
Hi Mike,
Sorry to bother you again. I believe this is the last bit of my TSSEM analysis.
I've tried to follow your R codes used in Schutte Keng and Cheung 2021 paper (see the link below) to test the hypothesis that the direct effect equalled the indirect effect (although I used the wls function, not the TSSEM2 function because I have to account for the dependent effect sizes of the studies included in my meta-analysis). However, the console of my R returned an error message saying that 'Running WLS Correlation with 5 parameters'.
Moreover, I reckon the ANOVA was not carried out successfully because all p values are 'NA'. Please see below for the output. I've attached the R codes to this message as well.
Would you mind checking what's wrong with the codes?
Thank you for your time and help in advance.
Best wishes,
Iana
> anova(unadjusted.metaSEM$mx.fit, stage2b) 5 3.436296e-21 -4 10 NA NA NA 5 2.689899e-21 -3 10 NA NA NA
base comparison ep minus2LL df AIC diffLL diffdf p
1 WLS Correlation
2 WLS Correlation
R codes used in Schutte Keng and Cheung 2021 paper:
https://github.com/mikewlcheung/code-in-articles/blob/master/Schutte%20Keng%20and%20Cheung%202021/EI.md
Log in or register to post comments
I cannot reproduce the errors
Could you please post the data?
Log in or register to post comments
In reply to I cannot reproduce the errors by Mike Cheung
Hi Mike,
Yes of course. Please find the attached file for the data.
Best wishes,
Iana
Log in or register to post comments
It works fine if you use diag
Log in or register to post comments
In reply to It works fine if you use diag by Mike Cheung
Oh right! Although I still
Moreover, if I use diag.constraints=FALSE in wls() in the codes for stage2b, do I also have to use diag.constraints=FALSE in the codes for stage 2? Or is it okay if I keep diag.constraints=TRUE in the code for stage 2?
Log in or register to post comments
I didn't encounter any errors
Models with diag.constraints=TRUE and diag.constraints=FALSE are identical. Models with diag.constraints=FALSE tend to have better convergence, whereas models with diag.constraints=TRUE use constraints to compute the error variances. You may use diag.constraints=TRUE if there are no error messages.
Log in or register to post comments
In reply to I didn't encounter any errors by Mike Cheung
I see! That's great to know.
Log in or register to post comments