Announcement

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

  • Using weights and imputed data with med4way for mediation analysis

    Dear all,

    I'm considering using med4way for mediation analysis, but I would need to use non-response weights as well as perform the analysis on imputed data, ideally. In their paper Discacciati et al (2018) mention that 'Methods for missing data .. could be incorporated.' Has anyone used med4way on imputed data, and if so, what the extension of the command looks like? Are you aware that weighting can be added too?

    I would really appreciate to hear from you.

    Many thanks,
    Darina

  • #2
    I have not tried to do what you are proposing with med4way. I have a couple of thoughts, however. With regards to weights, it should in theory be possible using the options yregoptions() and mregoptions(), You should be able to add something like yregoptions(pw=XXX). Multiple imputation often works with commands that were not built by Stata but no guarantees. You need to use the following option in your model statement:
    Code:
    mi estimate, cmdok: med4way...
    I do not know if it will work. In this case, I'd probably run the y and m regressions with mi and the weights separately and then do so with med4way to see that results match.

    Comment


    • #3
      Hi Erik, thanks very much for your help. Running this on imputed data worked, but not adding the weight. The error I get is:' option pw not allowed'. This is my code, if you see something that is not right in my code:
      'mi estimate, cmdok: med4way outcome exposure mediator covariate(s), a0(0) a1(1) m(0) yreg(linear) mreg(logistic) yregoptions(pw=weigth) mregoptions(pw=weight) boot reps(100)'.
      Outcome is continuous, exposure and mediator are binary.

      Any other ideas about weighted med4way analysis?

      Many thanks,
      Darina

      Comment


      • #4
        Hello Darina,

        You can pass probability weights to the model for the outcome/mediator using yregoptions() and mregoptions() (as suggested by Erik, but with a different syntax).

        See the toy example below:

        Code:
        net get med4way, from("https://raw.githubusercontent.com/anddis/med4way/master/")
         use med4way_example_3.dta
        
        // generate toy weights - only for illustrative purposes
        set seed 68
        gen w = 1/runiform()
        
        // model for the outcome (with weights)
        hetregress CogPerform c.Encourage##c.Motivation SocStatus FamSize [pw = w]
        
        // model for the mediator (with weights)  
        hetregress Motivation Encourage SocStatus FamSize [pw = w]
        
        // med4way with pweights passed to the outcome and to the mediator model
        // using the options yregoptions() and mregoptions() - see help med4way
        // Note that the output from med4way for the model for the outcome and the
        // model for the mediator is identical to that from hetregress - as expected
        med4way CogPerform Encourage Motivation SocStatus FamSize, yreg(linear) mreg(linear) a0(33.91667) a1(34.91667) m(38.47) ///
            yregoptions(, [pw = w]) /// NOTE THE COMMA!
            mregoptions(, [pw = w]) //  NOTE THE COMMA!
        (Edit: the comma inside med4way's y/mregoptions() option is necessary to pass the weights to the regression commands *after* the options instead of before, as per usual.

        Code:
        sysuse auto, clear
        gen wg = 1/runiform()
        regress length weight headroom  [pw = wg], mse1
        regress length weight headroom, mse1, [pw = wg]
        )
        Last edited by Andrea Discacciati; 23 Apr 2024, 04:10.

        Comment


        • #5
          Hi again,

          Just wanted to share this, if helpful: added fw pw to regressml · anddis/med4way@a24bf75 · GitHub
          Thanks,
          Darina

          Comment


          • #6
            Thanks so much Andrea and Erik, the example was very helpful! Adding the mi commands and bootstraps to this was straightforward and all runs smoothly.

            Comment

            Working...
            X