## You are here

The OpenMx website will be down for maintenance from 9 AM EDT on Tuesday, September 17th, and is expected to return by the end of the day on Wednesday, September 18th. During this period, the backend will be updated and the website will get a refreshed look.

# How to generate A matrice and S matrice for the second stage of TSSEM?

20 posts / 0 new
Offline
Joined: 10/16/2021 - 12:33
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.

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#...

Offline
Joined: 10/08/2009 - 22:37
Dear Iana,

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

Offline
Joined: 10/16/2021 - 12:33
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

Best wishes,
Iana

Offline
Joined: 10/08/2009 - 22:37
Dear Iana,

Dear Iana,

You may refer to the following example:
https://github.com/mikewlcheung/code-in-articles/tree/master/Schutte%20Keng%20and%20Cheung%202021

Mike

Offline
Joined: 10/16/2021 - 12:33
Thank you so much Mike for

Thank you so much Mike for referring me to that link. It's very helpful :)

Best wishes,
Iana

Offline
Joined: 10/16/2021 - 12:33
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 Offline Joined: 10/08/2009 - 22:37 Hi Iana, 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 Offline Joined: 10/16/2021 - 12:33 Hi Mike, 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 Offline Joined: 10/08/2009 - 22:37 Hi Iana, 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 Offline Joined: 10/16/2021 - 12:33 Oh thank you for directing me Oh thank you for directing me to vec2symMat! I'll check it out :) Thank you Mike for your help again! That's very helpful :) Best wishes, Iana Offline Joined: 10/16/2021 - 12:33 Hi Mike, 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)...) Offline Joined: 10/08/2009 - 22:37 Some names of the arguments Some names of the arguments may be changed in different versions. You may refer to help(wls) for the correct names. Offline Joined: 10/16/2021 - 12:33 I see! Thank you Mike for I see! Thank you Mike for your prompt response! I found that the version of my R uses aCov :) Best wishes, Iana Offline Joined: 10/16/2021 - 12:33 Hi Mike, 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)
base comparison ep minus2LL df AIC diffLL diffdf p
1 WLS Correlation 5 3.436296e-21 -4 10 NA NA NA
2 WLS Correlation 5 2.689899e-21 -3 10 NA NA NA

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

File attachments:
Offline
Joined: 10/08/2009 - 22:37
I cannot reproduce the errors

I cannot reproduce the errors as I do not have the data.
Could you please post the data?

Offline
Joined: 10/16/2021 - 12:33
Hi Mike,

Hi Mike,

Yes of course. Please find the attached file for the data.

Best wishes,
Iana

File attachments:
Offline
Joined: 10/08/2009 - 22:37
It works fine if you use diag

It works fine if you use diag.constraints=FALSE in wls().

Offline
Joined: 10/16/2021 - 12:33
Oh right! Although I still

Oh right! Although I still got the error message of 'Running WLS Correlation with 5 parameters', the p values for the anova result no longer have NAs. I wonder if it is still okay to run the anova with such an error message?

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?

Offline
Joined: 10/08/2009 - 22:37
I didn't encounter any errors

I didn't encounter any errors (see the attached file).

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.

File attachments:
Offline
Joined: 10/16/2021 - 12:33
I see! That's great to know.

I see! That's great to know. Thank you so much for the explanation and help, Mike! That's super helpful :)