FloSchuberth / cSEM

Composite-based SEM
https://floschuberth.github.io/cSEM/
GNU General Public License v3.0
28 stars 7 forks source link

Mediation analysis for Composite-Based Structural Equation Modeling in cSEM #435

Closed JulianGaviriaL closed 2 years ago

JulianGaviriaL commented 3 years ago

Dear cSEM experts,

I wonder how can I run my mediation analysis in cSEM (i.e., direct and indirect effects). I've read that the syntax is lavaan-based. That's why I tried the following:

myDATA<- read_excel("XXX/data.xlsx", sheet = "data")

# Composite variables
  X <~ Brain_prev1 + Brain_prev2 + Brain_prev3 + Brain_prev4 + Brain_prev5
  M <~ behavior1 + behavior2 + behavior3 + behavior4
  Y <~ Brain_curr1 + Brain_curr2 + Brain_curr3 + Brain_curr4 + Brain_curr5
#Running model:
model <- '
           # direct effect
             Y ~ c*X
           # mediator
             M ~ a*X
             Y ~ b*M
           # indirect effect (a*b)
             ab := a*b
           # total effect
             total := c + (a*b)  
             '
 res <- csem(.data=myDATA,.model=model, .resample_method = "bootstrap", .R=1000)

Unfortunately I get following error message:

Error: The following error occured in the `parseModel()` function:
Only a subset of population values given. Please specify all population values or none.

data.xlsx

My source for the medition syntax in lavann is: https://lavaan.ugent.be/tutorial/mediation.html

Many thanks in advance,

Julian

FloSchuberth commented 3 years ago

Dear @JulianGaviriaL ,

in cSEM you cannot label your coefficients (a, b) as in lavaan. Moreover, if you want to specifiy transformations that are based on cSEM outputs such as total effects, you need to use the .user_funs argument. However, in your case, this is not necessary because all the relevant output is provided by the summarize function. Please respcify your model as follows: model <- '

direct effect

         Y ~ X
       # mediator
         M ~ X
         Y ~ M
         '

Be aware that cSEM cannot deal with observed variables in the strutcural model directly. They must be modeled as single indicator constructs, i.e., you need to specify a composite or reflective measurement model for X, M and Y. Consequently, the specified model will still produce an error.

Subsequently, you can estimate your model (given you have further specified X,Y and M): res <- csem(.data=myDATA,.model=model, .resample_method = "bootstrap", .R=1000)

Using the summarize function, you can get the desired output: summarize(res)

HTH

Best regards, Florian

JulianGaviriaL commented 3 years ago

Thank you very much Florian !

JulianGaviriaL commented 2 years ago

Dear @FloSchuberth

Given the model:

model <- "
  # Composite variables
  X <~ Brain_prev1 + Brain_prev2
  M <~ behavior1 + behavior2
  Y <~ Brain_curr1 + Brain_curr2

           # direct effect
             Y ~ X
             # mediator
             M ~ X
             Y ~ M
         "
res <- csem(.data=myDATA,.model=model, .resample_method = "bootstrap", .R=10000)

where:

a= M ~ X
b= Y ~ M
c'= Y ~ X

How can I compute c= c'+a*b? Namely, how can I obtain the estimate, Standard Error, T-stat, p-values and CI(95%) of the total effect?

P.D: the "Estimated total effects" section from summarize() provides the info about the paths, but not the total effect. Conversely, "Estimated indirect effects" corresponds to the indirect effect [a x b (Nitzl, et al., 2016)].

Many thanks in advance.

FloSchuberth commented 2 years ago

Dear Julian,

so you see the total effect section. In this section, Y ~ X stands for the total effect, not the path coefficient/direct effect. It should be different from the path coefficient Y ~ X that you find in the top of the summarize output. Can you please confirm this.

Best regards, Florian

JulianGaviriaL commented 2 years ago

Dear @FloSchuberth

Thanks for your response. Extra bonus since it came in the weekend :-)

Two final comments before closing this issue:

Please find below my cSEM output of "estimated path coefficients:" and "estimated total effects" respectively.

Estimated path coefficients:
============================
                                                       CI_percentile   
  Path     Estimate  Std. error   t-stat.   p-value         95%        
  M ~ X     -0.8261      0.0457  -18.0819    0.0000 [-0.9194;-0.7354 ] 
  Y ~ X      0.2034      0.2571    0.7912    0.4288 [-0.2888; 0.7551 ] 
  Y ~ M     -0.6363      0.2552   -2.4932    0.0127 [-1.0669;-0.0450 ] 
------------------------------------ Effects -----------------------------------

Estimated total effects:
========================
                                                              CI_percentile   
  Total effect    Estimate  Std. error   t-stat.   p-value         95%        
  M ~ X            -0.8261      0.0457  -18.0819    0.0000 [-0.9194;-0.7354 ] 
  Y ~ X             0.7290      0.0904    8.0672    0.0000 [ 0.5241; 0.8757 ] 
  Y ~ M            -0.6363      0.2552   -2.4932    0.0127 [-1.0669;-0.0450 ] 

Best regards,

FloSchuberth commented 2 years ago

Hey Julian,

Indeed for these two the total and the direct effect (estimated path coefficient) are the same. The reason for that is that there is no indirect effect of the independent variable (X) on the dependent variable (M). The same is true for Y~M. In this case the total effect equals the direct effect.

Best regards, Florian


Von: JulianGaviriaL @.***> Gesendet: Sonntag, 25. Juli 2021 18:26:00 An: M-E-Rademaker/cSEM Cc: Schuberth, F. (ET); Mention Betreff: Re: [M-E-Rademaker/cSEM] Mediation analysis for Composite-Based Structural Equation Modeling in cSEM (#435)

Dear @FloSchuberthhttps://github.com/FloSchuberth

Thanks for your response. Extra bonus since it came in the weekend :-)

Two final comments before closing this issue:

Please find below my cSEM output of "estimated path coefficients:" and "estimated total effects" respectively.

Estimated path coefficients:

                                                   CI_percentile

Path Estimate Std. error t-stat. p-value 95% M ~ X -0.8261 0.0457 -18.0819 0.0000 [-0.9194;-0.7354 ] Y ~ X 0.2034 0.2571 0.7912 0.4288 [-0.2888; 0.7551 ] Y ~ M -0.6363 0.2552 -2.4932 0.0127 [-1.0669;-0.0450 ]

------------------------------------ Effects -----------------------------------

Estimated total effects:

                                                          CI_percentile

Total effect Estimate Std. error t-stat. p-value 95% M ~ X -0.8261 0.0457 -18.0819 0.0000 [-0.9194;-0.7354 ] Y ~ X 0.7290 0.0904 8.0672 0.0000 [ 0.5241; 0.8757 ] Y ~ M -0.6363 0.2552 -2.4932 0.0127 [-1.0669;-0.0450 ]

Best regards,

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/M-E-Rademaker/cSEM/issues/435#issuecomment-886225675, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD5KRRCWL6FQNTHVC7DTM6LTZQ3JRANCNFSM47QKBG2A.

JulianGaviriaL commented 2 years ago

Thank you very much Florian, Best regards,