Announcement

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

  • Average marginal effect (margins dydx) in multinomial regression (mlogit) for one outcome against each of the others

    Hello,

    I am running a multinomial regression (mlogit), and I can't find a way to use the margins, dydx command to calculate the average marginal effect of a predictor on the probability of one outcome against each of the others, rather than the probability of one outcome against all the others (which is the default).

    Here is an example

    Code:
    webuse margex
    logistic outcome age, or
    /* The odds ratio refers to the probability of outcome == 1 rather than == 0 */
    
    margins , dydx(age)
    /* This is the average marginal effect of age on the probability of outcome == 1 rather than == 0 */
    
    mlogit group age, rrr
    /* The odds ratio in the second row refers to the probability of outcome == 2 rather than == 1,
     while the one in the third row refers to the probability of outcome == 3 rather than == 1 */
    
    margins , dydx(age)
    /* These are the average marginal effects of age on: (1) the probability of outcome == 1 rather than the other two, (2) the probability of outcome  == 2 rather than the other two, (3) the probability of outcome == 3 rather than the other two */

    Ideally, I would like the average marginal effect for each of the three pairwise comparisons (if we may call it like that), i.e. the average marginal effect of age on the probability of outcome == 2 rather than == 1, then 1 against 3, and 2 against 3, just like the odds ratios table (if one runs the mlogit command twice and changes the base outcome), or the very margins,dydx command for binomial logistic regression.

    Finally, I would also like to plot this, using marginsplot or any other useful command.

    Many thanks!

    Giuseppe
    Last edited by Giuseppe Ciccolini; 11 Dec 2020, 09:36.

  • #2
    Hi,
    I would ask you if you manage to solve this problem? I have the same one.
    Thanks for the answer

    Comment


    • #3
      Hi I didn't unfortunately!

      Comment


      • #4
        Update: the only "solution" I found is computing the predicted probability (not the average marginal effect, my initial aim) of one outcome against each of the others (instead of the probability of one outcome against all the others, which is the default). I do it in the following way: I compute the predicted probability of, say, outcome 3 out of the sum of the probability of outcome 3 and of outcome 1 (or 2), rather than 100%. The intuition is that this is basically what logistic regression does when you exclude one of the three outcomes.
        Code:
        * Same example as above
        webuse margex, clear
        mlogit group age, rrr baseoutcome(3)
        
        * The default (each outcome versus the other two)
        margins , at(age = (20 60)) atmeans
        
        * 3 vs 1 (excluding 2)
        margins , at(age = (20 60)) atmeans ///
                expression( ///
                    predict(outcome(3)) / (predict(outcome(3)) + predict(outcome(1))) ///
                    )
        
        * 3 vs 2
        margins , at(age = (20 60)) atmeans ///
                expression( ///
                    predict(outcome(3)) / (predict(outcome(3)) + predict(outcome(2))) ///
                    )
                    
        * One can get to this with logistic regression too
        foreach i in 1 2 {
            gen group3vs`i' = .
            replace group3vs`i' = 0 if group == `i'
            replace group3vs`i' = 1 if group == 3
            logistic group3vs`i' age, or
            margins , at(age = (20 60)) atmeans
        }

        Comment


        • #5
          That said, the above solution doesn't achieve what I wanted, that is getting a sense of the magnitude of the average marginal effects with their confidence intervals (e.g. to show that "3 vs 1" and "3 vs 2" are pretty the same). If one wants to get the predicted probabilities I find that the following solution (the second graph) is more appropriate (although there are no confidence intervals): https://www.statalist.org/forums/for...-an-area-graph

          Comment


          • #6
            Also, the option atmeans in the above code is unintended.

            Code:
            * Same example as above
            webuse margex, clear
            mlogit group age, rrr baseoutcome(3)
            
            * The default (each outcome versus the other two)
            margins , at(age = (20 60)) 
            
            * 3 vs 1 (excluding 2)
            margins , at(age = (20 60)) ///
                    expression( ///
                        predict(outcome(3)) / (predict(outcome(3)) + predict(outcome(1))) ///
                        )
            
            * 3 vs 2
            margins , at(age = (20 60)) ///
                    expression( ///
                        predict(outcome(3)) / (predict(outcome(3)) + predict(outcome(2))) ///
                        )
                        
            * One can get to this with logistic regression too
            foreach i in 1 2 {
                gen group3vs`i' = .
                replace group3vs`i' = 0 if group == `i'
                replace group3vs`i' = 1 if group == 3
                logistic group3vs`i' age, or
                margins , at(age = (20 60)) 
            }

            Comment


            • #7
              Andrew Musau has kindly come up with a solution, by replacing the coefficients' matrix and VCV of a binary logit model with the pair from the multinomial logit. It is based on erepost from SSC.

              Code:
              ssc install erepost
              
              webuse margex, clear
              mlogit group age, baseoutcome(1)
              mat coef  = e(b)[1, "2:"]
              mat vcv  = e(V)["2:","2:"]
              
              foreach i of numlist 1/3 {
                  gen isgroup`i' = group == `i'
              }
              logit isgroup2 age if inlist(group,1,2), or
              //margins, dydx(age)
              erepost b = coef, rename
              erepost V = vcv, rename
              est sto m1
              est replay m1
              margins, dydx(age)

              Comment

              Working...
              X