Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Causal mediation with multiple mediators (continuous and binary) in same model

    Hi everyone,
    Is there any way to produce causal mediation effects (NIE, NDE, TE) for a model that has multiple mediators of different distributions (parallel mediators)?

    Using Stata 18.5, I ran a gsem model that has a continuous dependent variable, binary treatment, and 6 mediator variables- 4 are continuous (bpi_avg_std, bpi_inter_avg_std, psq3_std, and se_index_std) and 2 are binary (postop_cr_ae_unsched_yn and postop_cr_rescue). The model produced estimates for the 'a' and 'b' effects but I want to calculate the NIE, NDE, and TE. I could use nlcom to estimate the indirect, direct, and total effects but this would not be accurate because of the use of both continuous and binary mediator variables. The nlcom command appears to overestimate the effect of the binary mediators.

    For simpler models in which we were looking at each mediator pathway independently, I used the mediate command to specify the NIE, NDE, and TE but I do not see that I can use mediate with the parallel model of multiple mediators of different distributions.

    Code:
    /*The gsem model:*/
    gsem (2.opioid -> overall_satisfied_postop, family(gaussian) link(identity)) (2.opioid -> bpi_avg_std, family(gaussian) link(identity)) (2.opioid -> bpi_inter_avg_std, family(gaussian) link(identity)) (2.opioid -> psq3_avg_std, family(gaussian) link(identity)) (2.opioid -> se_index_std, family(gaussian) link(identity)) (2.opioid -> 1.postop_cr_ae_unsched_yn, family(multinomial) link(logit)) (2.opioid -> 1.postop_cr_rescue, family(multinomial) link(logit)) (bpi_avg_std -> overall_satisfied_postop, family(gaussian) link(identity)) (bpi_inter_avg_std -> overall_satisfied_postop, family(gaussian) link(identity)) (psq3_avg_std -> overall_satisfied_postop, family(gaussian) link(identity)) (se_index_std -> overall_satisfied_postop, family(gaussian) link(identity)) (1.postop_cr_ae_unsched_yn -> overall_satisfied_postop, family(gaussian) link(identity)) (1.postop_cr_rescue -> overall_satisfied_postop, family(gaussian) link(identity)) (M1[site] -> overall_satisfied_postop, family(gaussian) link(identity)), covstruct(_lexogenous, diagonal) vce(cluster site) latent(M1 ) nocapslatent
    
    /*The nlcom statement:*/
    nlcom (nlcom_pain: _b[bpi_avg_std:2.opioid]*_b[overall_satisfied_postop:bpi_avg_std]) (nlcom_pint: _b[bpi_inter_avg_std:2.opioid]*_b[overall_satisfied_postop:bpi_inter_avg_std]) (nlcom_sint: _b[psq3_avg_std:2.opioid]*_b[overall_satisfied_postop:psq3_avg_std]) (nlcom_ssev: _b[se_index_std:2.opioid]*_b[overall_satisfied_postop:se_index_std]) (nlcom_appt: _b[overall_satisfied_postop:1.postop_cr_ae_unsched_yn]*_b[1.postop_cr_ae_unsched_yn:2.opioid]) (nlcom_rmed: _b[overall_satisfied_postop:1.postop_cr_rescue]*_b[1.postop_cr_rescue:2.opioid])
    
    /*Example mediate commands for individual models:*/
    mediate ( overall_satisfied_postop) (bpi_avg_std) (opioid), vce(cluster site)
    If anyone has any thoughts or comments, I would be incredibly appreciative. Thanks so much for your time- Tracy

    Data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long dag byte overall_satisfied_postop long opioid float(bpi_avg_std bpi_inter_avg_std psq3_avg_std se_index_std) byte(postop_cr_ae_unsched_yn postop_cr_rescue)
    1 1 2  -.3344965   .0811432 -1.0930908 -.21633343 0 0
    1 3 2  1.8984196  2.1327698  2.1251218   5.561748 0 0
    1 1 1  -.8095852  -1.471439 -1.0930908  -.7416136 0 0
    1 3 1  -.6433042  .13659258 -1.0930908  -.7416136 0 0
    1 2 2 -.09695224 -1.0278442 -1.0930908  -.9167069 0 0
    1 2 1  -.8333396  -1.305091 -.55672204  -.4789735 0 0
    1 1 2  .16434646  -.8060468 -.02035328  1.0093203 1 0
    1 3 2   .6156806   .5801875 -.55672204  -.8291602 . .
    1 1 2 -1.2609193 -1.0832937  .51601547 -.12878677 0 0
    1 2 2  .03963568  -.6396986 -.55672204  -.9167069 . .
    1 2 2   1.589612  1.8000735  2.1251218  .22140007 0 0
    1 2 2 -1.2609193  -.4733505 -.02035328  -.7416136 0 0
    1 3 2  1.0590967  -.8892207  1.0523843  .38427755 0 0
    1 1 2 -.59579533 -1.1387429 -1.0930908 -.12878677 0 0
    1 4 1   .4969085  2.1327698  2.1251218   .8342269 1 0
    1 3 2   .4018906  -1.305091 -.55672204 -.21633343 0 0
    1 1 1  -1.237165  -.3070023 -1.0930908 -.19393773 0 0
    1 3 1   1.138278   .3583899   1.588753  -.9167069 0 0
    1 2 1 -1.1183927  -1.471439 -1.0930908  -.9167069 0 0
    1 1 2  -.9521117 -1.0832937 -1.0930908  -.7416136 0 0
    1 2 2   .8215523   .8574342          .   3.365299 0 0
    1 2 2  .11683752  -.4179011   1.588753  1.7972405 0 0
    1 2 1  -.5007776  -.9169455 -.02035328  -.9167069 0 0
    2 3 2  -.6670585  -.4733505 -.55672204  -.9167069 0 0
    2 1 2  -.8333396  -.7505974 -.55672204  -.9167069 0 0
    2 2 1   .7344528   .4138393  .51601547  -.3038801 0 0
    2 2 2  .16434646 -1.0832937 -.02035328  -.9167069 0 0
    2 3 1  1.3520677  -.5287999  .51601547  -.3914268 0 0
    2 1 1  -1.355937  -.9723948 -1.0930908  .04630665 0 0
    2 2 2 -.09695224 -1.0278442  .51601547  -.8291602 0 0
    2 2 2 -1.4509547  -.6396986 -1.0930908  -.8291602 0 0
    2 2 2  .23560967  -.8060468 -.55672204 -.56652015 1 0
    2 1 1  -.5482864 -.14065439 -.02035328  -.8291602 0 0
    2 . 2 -1.1480857  -1.221917 -1.0930908  -.9167069 . .
    2 2 2  1.4470856   .9128836  1.0523843  -.9167069 0 1
    2 2 2   .9957513    .968333  .51601547   2.147427 0 0
    2 5 1  2.2666132   2.520915  2.1251218   2.413194 0 1
    2 2 1  -1.522218  -1.305091 -1.0930908  -.9167069 0 0
    2 1 2  -.2632333  -.5842493 -1.0930908  -.7416136 0 0
    2 1 2   .6334964   .0256938  1.0523843 -.05935316 0 0
    2 1 1 -1.7122535  -1.471439 -1.0930908  -.9167069 0 0
    2 1 2 -1.2134105 -1.1941923  .51601547  -.9167069 0 0
    2 2 2  .18810086  1.1901306  .51601547  1.9723338 0 0
    2 3 2  2.0409462  1.0792319  1.0523843 -.21633343 0 0
    2 1 2   .5681718  1.0792319  1.0523843  2.2349737 0 0
    2 . 1  1.7796475  1.9109722  2.1251218 -.21633343 . .
    3 2 1  -.6908129  -.7505974 -1.0930908  .04630665 0 0
    3 1 1  1.0195059  .52473813 -.02035328  1.0093203 0 0
    3 3 1  1.3283135    .968333  1.0523843 -.04124002 0 0
    3 1 1   .2118554  1.1346812 -.55672204  1.4470537 0 0
    3 2 1  -.7145675  -.9169455 -.55672204  -.6540669 0 0
    3 2 2  1.3995768   .8019848  2.1251218  .13385332 0 0
    3 2 1  1.7558932  2.3545675   1.588753  -.7416136 1 1
    3 2 2  1.8984196  1.3010292  .51601547   1.359507 0 0
    3 2 2   .4018906  1.1901306  1.0523843   1.359507 1 0
    3 3 1   .7344528   .4692887 -.55672204 -.21633343 0 0
    3 2 2  -.4770232  -.4733505 -.55672204  -.3038801 0 0
    3 2 2  .06932872   .7465357  1.0523843 -.21633343 0 0
    3 3 2   .6631894   .3583899 -1.0930908  -.8291602 0 0
    3 1 2   .4018906   -.861496 -.02035328  .13385332 0 0
    3 2 2  -.3463738   .6079121 -1.0930908 -.02873334 0 0
    3 1 2 -.14446117   .3583899 -.55672204   .5715868 0 0
    4 1 1  -.8511554  -.8892207 -.02035328 -.47272015 0 0
    4 2 2  .09308312  -.4733505 -.02035328  .48404005 0 0
    4 1 1   .5919261  -1.471439 -1.0930908  -.9167069 0 0
    4 2 1 -1.2134105  -.4179011 -1.0930908  -.9167069 0 0
    4 2 2  -.9283573  -.4733505 -.02035328   .5715868 0 0
    4 1 1  1.0432603  1.0237824 -.55672204  -.3914268 0 0
    4 1 1  -.9283573   .3583899  .51601547   4.686281 0 0
    4 1 1 -.04944343 -1.1387429 -1.0930908  -.9167069 0 0
    4 3 2  1.0432603   1.578276   1.588753  1.4470537 0 0
    4 1 1 -.09695224 -1.4159898 -1.0930908  -.6540669 0 0
    4 4 2   2.611053   2.021871  2.1251218  1.7972405 1 1
    4 2 2  -.6195498   .9128836  .51601547  -.7416136 0 0
    4 2 2  1.3283135  .24749137  1.0523843  -.4789735 0 0
    4 2 1  -.6433042 -.14065439  1.0523843  -.6947135 0 0
    4 2 2  -1.023375  1.1346812 -.55672204  .04630665 0 0
    4 2 2  -.9283573 -1.2496417 -.55672204  -.3914268 0 0
    4 2 1  1.9934375  2.3545675  2.1251218  2.0598805 1 0
    4 2 1  .06932872    .192042   1.588753 -.04124002 0 0
    4 2 1 -1.1421471  -.3624517 -1.0930908  -.6540669 0 0
    4 2 2  1.3995768   2.188219 -.55672204  2.2349737 0 0
    4 2 1   .2118554  .52473813  .51601547 -.21633343 0 0
    4 1 1   .8057161  -.5287999  .51601547   2.585161 0 0
    4 1 1  -.8808484  -.4733505 -.55672204  -.7416136 0 0
    4 2 2 -1.0471294 -1.0832937 -.02035328  -.8291602 0 0
    5 3 2  -.9204392  -.9723948 -1.0930908 -.19393773 0 0
    5 2 2  -1.474709  -.7505974 -1.0930908  -.6540669 0 0
    5 2 2 -1.7122535  -1.471439 -1.0930908  -.6540669 0 0
    5 3 2  -1.474709  -1.305091 -1.0930908  -.9167069 0 0
    5 1 1 -1.3321825  -1.471439 -1.0930908  -.8291602 0 0
    5 2 1  -.9996206  -.8060468 -.02035328  -.3914268 0 0
    5 2 2 -1.1183927 -.08520499 -.55672204  -.3914268 0 0
    5 1 2  -.7383219  -.7505974 -.55672204 -.56652015 0 0
    5 2 2  .44939965  -.5287999 -1.0930908  1.2719603 0 0
    5 2 2  -.8333396 -1.1941923 -1.0930908  -.9167069 0 0
    5 2 1  -.3344965  -.3624517   1.588753 -.12878677 0 0
    5 3 1  .47315395   .4692887 -.02035328  -.7416136 0 0
    5 2 1   .5681718  1.3564786  2.1251218  -.6540669 0 0
    5 2 2  -.7620763 -1.1387429 -1.0930908  -.4789735 0 0
    end
    label values opioid opioid
    label def opioid 1 "Non-Opioid", modify
    label def opioid 2 "Opioid", modify
    Last edited by Tracy Andrews; 03 Nov 2025, 14:18. Reason: Clarification of model- parallel rather then mediator to mediator pathway

  • #2
    Have a look at gformula and KHB, both from SSC. I am not sure if they do everything you want to.
    https://journals.sagepub.com/doi/pdf...867X1201100401 (see especially example 2).
    https://journals.sagepub.com/doi/pdf...867x1101100306
    Best wishes

    Stata 18.0 MP | ORCID | Google Scholar

    Comment


    • #3
      Thank you Felix for the suggestions. Unfortunately, gformula won't allow for all of the equations to be estimated and it appears that all of the mediators have to be of the same distribution for khb.

      I would estimate the individual mediator models and then calculate the total effect across models but they are not completely independent.

      Comment


      • #4
        See this response to an earlier Statalist thread about multiple mediators in the causal framework. The R package CMAverse seems to be able to do this with at least a couple of mediators.

        Comment


        • #5
          Thanks Erik for the suggestion.
          I had been working with nlcom to get the indirect and total effects but was having trouble with the two different distributions.
          I found an article that helped me write the specific equation to use for the binary mediators and have been able to make it work. I am including the code below for anyone who is interested.

          Code:
          /*gsem model with all 6 mediators: pain, pain interference, sleep interference, se severity, clinic visit, and rescue med*/
          
          gsem (2.opioid -> overall_satisfied_postop, family(gaussian) link(identity)) (2.opioid -> /*PAIN*/ bpi_avg_std, family(gaussian) link(identity)) (2.opioid -> /*PAIN INTERFERENCE*/ bpi_inter_avg_std, family(gaussian) link(identity)) (2.opioid -> /*SLEEP INTERFERENCE*/ psq3_avg_std, family(gaussian) link(identity)) (2.opioid -> /*SE SEVERITY*/ se_index_std, family(gaussian) link(identity)) (2.opioid -> /*CLINIC VISIT*/ 1.postop_cr_ae_unsched_yn, family(multinomial) link(logit)) (2.opioid -> /*RESCUE MED*/ 1.postop_cr_rescue, family(multinomial) link(logit)) (bpi_avg_std -> overall_satisfied_postop, family(gaussian) link(identity)) (bpi_inter_avg_std -> overall_satisfied_postop, family(gaussian) link(identity)) (psq3_avg_std -> overall_satisfied_postop, family(gaussian) link(identity)) (se_index_std -> overall_satisfied_postop, family(gaussian) link(identity)) (1.postop_cr_ae_unsched_yn -> overall_satisfied_postop, family(gaussian) link(identity)) (1.postop_cr_rescue -> overall_satisfied_postop, family(gaussian) link(identity)) (M1[site] -> overall_satisfied_postop, family(gaussian) link(identity)), covstruct(_lexogenous, diagonal) vce(cluster site) latent(M1 ) nocapslatent
          
          /*nlcom to produce the 6 indirect effects and the total effect*/
          nlcom /*PAIN*/ (pain: _b[bpi_avg_std:2.opioid]*_b[overall_satisfied_postop_std:bpi_avg_std]) /*PAIN INTERFERENCE*/ (pint: _b[bpi_inter_avg_std:2.opioid]*_b[overall_satisfied_postop_std:bpi_inter_avg_std]) /*SLEEP INTERFERENCE*/ (sint: _b[psq3_avg_std:2.opioid]*_b[overall_satisfied_postop_std:psq3_avg_std]) /*SE SEVERITY*/ (ssev: _b[se_index_std:2.opioid]*_b[overall_satisfied_postop_std:se_index_std]) /*CLINIC VISIT*/(appt: _b[overall_satisfied_postop_std:1.postop_cr_ae_unsched_yn] *((exp(_b[1.postop_cr_ae_unsched_yn:_cons] + _b[1.postop_cr_ae_unsched_yn:2.opioid])/ (1 + exp(_b[1.postop_cr_ae_unsched_yn:_cons] + _b[1.postop_cr_ae_unsched_yn:2.opioid]))) - (exp(_b[1.postop_cr_ae_unsched_yn:_cons])/ (1 + exp(_b[1.postop_cr_ae_unsched_yn:_cons]))))) /*RESCUE MED*/ (rmed: _b[overall_satisfied_postop_std:1.postop_cr_rescue] *((exp(_b[1.postop_cr_rescue:_cons] + _b[1.postop_cr_rescue:2.opioid])/ (1 + exp(_b[1.postop_cr_rescue:_cons] + _b[1.postop_cr_rescue:2.opioid]))) - (exp(_b[1.postop_cr_rescue:_cons])/ (1 + exp(_b[1.postop_cr_rescue:_cons]))))) /*TOTAL EFFECT*/ (teff: _b[overall_satisfied_postop_std:2.opioid] + /*PAIN*/ _b[bpi_avg_std:2.opioid]*_b[overall_satisfied_postop_std:bpi_avg_std] + /*PAIN INTERFERENCE*/ _b[bpi_inter_avg_std:2.opioid]*_b[overall_satisfied_postop_std:bpi_inter_avg_std] + /*SLEEP INTERFERENCE*/ _b[psq3_avg_std:2.opioid]*_b[overall_satisfied_postop_std:psq3_avg_std] + /*SE SEVERITY*/ _b[se_index_std:2.opioid]*_b[overall_satisfied_postop_std:se_index_std] + /*CLINIC VISIT*/ _b[overall_satisfied_postop_std:1.postop_cr_ae_unsched_yn] *((exp(_b[1.postop_cr_ae_unsched_yn:_cons] + _b[1.postop_cr_ae_unsched_yn:2.opioid])/ (1 + exp(_b[1.postop_cr_ae_unsched_yn:_cons] + _b[1.postop_cr_ae_unsched_yn:2.opioid]))) - (exp(_b[1.postop_cr_ae_unsched_yn:_cons])/ (1 + exp(_b[1.postop_cr_ae_unsched_yn:_cons])))) + /*RESCUE MED*/ _b[overall_satisfied_postop_std:1.postop_cr_rescue] *((exp(_b[1.postop_cr_rescue:_cons] + _b[1.postop_cr_rescue:2.opioid])/ (1 + exp(_b[1.postop_cr_rescue:_cons] + _b[1.postop_cr_rescue:2.opioid]))) - (exp(_b[1.postop_cr_rescue:_cons])/ (1 + exp(_b[1.postop_cr_rescue:_cons])))))

          Comment


          • #6
            Tracy Andrews Can you share the article that helped you write out the nlcom equation?

            Comment

            Working...
            X