Announcement

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

  • Log reg using a interaction term - subtracting "individual" ORs

    Hi,

    I'm doing a log reg using a interaction term for gender and education. I want to get the OR for e.g. women with low education. Do I need to multiple the ORs with each other (e.g. for women with low education, 1.59 x 1.46 x 0.81), or can I use some kind of command to subtract the specific ORs for a specific gender + education-level?
    Code:
    logistic hyphens gender##education age i.vad  i.inotropes bmi i.smoking i.cmv i.init_stat i.lvad i.mi 
    
    Logistic regression            Number of obs =    24,979
                LR chi2(67)   =    4481.60
                Prob > chi2   =    0.0000
    Log likelihood = -20007.416            Pseudo R2     =    0.1007
    
                        
    hyptens           Odds ratio    Std. err.        z         P>z     [95% conf.    interval]
                        
    1.gender    1.592065    .0920858    16.77   0.000    1.919146    2.280564
        
    education   
    Low            1.457316    .070604    16.26   0.000    1.342967    1.999986
    High           .6490592    .0429516    -5.04   0.000    .5569423    .8381556
        
    gender#education  
    1#Low        .8120516    .0543957    -3.12   0.002    .7111679    .9250097
    1#High       .9656718    .1030279    -0.51   0.608    .7638208    1.170759
    Grateful for any help!

  • #2
    Vilma:
    I do hope that the following toy-example, focused on a black smoker is helpful:
    Code:
    . use "https://www.stata-press.com/data/r17/lbw.dta"
    (Hosmer & Lemeshow data)
    
    . logit low i.race##i.smoke if race<=2, allbase
    
    Iteration 0:   log likelihood =  -72.18867  
    Iteration 1:   log likelihood = -64.637711  
    Iteration 2:   log likelihood = -64.209477  
    Iteration 3:   log likelihood =  -64.20707  
    Iteration 4:   log likelihood =  -64.20707  
    
    Logistic regression                                     Number of obs =    122
                                                            LR chi2(3)    =  15.96
                                                            Prob > chi2   = 0.0012
    Log likelihood = -64.20707                              Pseudo R2     = 0.1106
    
    ----------------------------------------------------------------------------------
                 low | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -----------------+----------------------------------------------------------------
                race |
              White  |          0  (base)
              Black  |   1.514128   .7522693     2.01   0.044      .039707    2.988548
                     |
               smoke |
          Nonsmoker  |          0  (base)
             Smoker  |   1.750517   .5982764     2.93   0.003     .5779164    2.923117
                     |
          race#smoke |
    White#Nonsmoker  |          0  (base)
       White#Smoker  |          0  (base)
    Black#Nonsmoker  |          0  (base)
       Black#Smoker  |   -.556594   1.032236    -0.54   0.590    -2.579739    1.466551
                     |
               _cons |  -2.302585   .5244044    -4.39   0.000    -3.330399   -1.274771
    ----------------------------------------------------------------------------------
    *///let's calculate the linear predictor of a black race individual who smokes///*
    . di ( 1.514128+ 1.750517 -.556594 -2.302585)
    .405466
    
    *///now let's compare our calculation by hand with the one provided by Stata///*
    
    . predict linear, xb
    
    . list id low race smoke linear if race==2 & smoke==1
    
         +---------------------------------------+
         |  id   low    race    smoke     linear |
         |---------------------------------------|
     29. | 115     0   Black   Smoker   .4054651 |
     33. | 119     0   Black   Smoker   .4054651 |
     41. | 128     0   Black   Smoker   .4054651 |
     79. | 172     0   Black   Smoker   .4054651 |
    133. |  11     1   Black   Smoker   .4054651 |
         |---------------------------------------|
    157. |  40     1   Black   Smoker   .4054651 |
    165. |  50     1   Black   Smoker   .4054651 |
    171. |  59     1   Black   Smoker   .4054651 |
    172. |  60     1   Black   Smoker   .4054651 |
    173. |  61     1   Black   Smoker   .4054651 |
         +---------------------------------------+
    
    *///eventually, let's convert the linear predictor of our interest into the
    ///corresponding odds*     
    . di exp(.4054651)
    1.5
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Carlo, thank you so much for your help! There is no way of doing this with the ORs from the logistic command directly?

      Comment


      • #4
        Hello Vilma Antonov. I'm not sure I understand exactly what you want to do, but perhaps this variation on Carlo's example will help.

        Code:
        clear
        use "https://www.stata-press.com/data/r17/lbw.dta"
        logit low i.race##i.smoke if race<=2, allbase
        *logit, coeflegend
        // Use the coefficients to compute the log-odds & odds of
        // the outcome for a black smoker
        display _newline ///
        "Log-odds of outcome for a black smoker = "  ///
        _b[2.race] + _b[1.smoke] + _b[2.race#1.smoke] + _b[_cons] _newline ///
        "    Odds of outcome for a black smoker = "  ///
        exp(_b[2.race] + _b[1.smoke] + _b[2.race#1.smoke] + _b[_cons])
        
        // Use -margins- to show the log-odds of the outcome for a black smoker
        margins, at(race==2 smoke==1) exp(predict(xb))
        // Use -margins- to show the odds of the outcome for a black smoker
        margins, at(race==2 smoke==1) exp(exp(predict(xb)))
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          Thank you Bruce!

          I have used the logistic command instead of logit, and was just wondering if there is any way you can calculate the odds ratio for e.g. black smokers without having to use the logit command and calculating with the coefficients. I remember someone telling me that you could, but have not been able to find anything like it... otherwise I'll just use this method

          Comment


          • #6
            Vilma:
            as an aside to Bruce's helpful explanation, sticking with my previous example you may want to try:
            Code:
            .  use "https://www.stata-press.com/data/r17/lbw.dta"
            (Hosmer & Lemeshow data)
            
            . logit low i.race##i.smoke if race<=2, allbase or
            
            Iteration 0:   log likelihood =  -72.18867  
            Iteration 1:   log likelihood = -64.637711  
            Iteration 2:   log likelihood = -64.209477  
            Iteration 3:   log likelihood =  -64.20707  
            Iteration 4:   log likelihood =  -64.20707  
            
            Logistic regression                                     Number of obs =    122
                                                                    LR chi2(3)    =  15.96
                                                                    Prob > chi2   = 0.0012
            Log likelihood = -64.20707                              Pseudo R2     = 0.1106
            
            ----------------------------------------------------------------------------------
                         low | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
            -----------------+----------------------------------------------------------------
                        race |
                      White  |          1  (base)
                      Black  |   4.545455   3.419406     2.01   0.044     1.040506    19.85684
                             |
                       smoke |
                  Nonsmoker  |          1  (base)
                     Smoker  |   5.757576   3.444621     2.93   0.003     1.782321    18.59916
                             |
                  race#smoke |
            White#Nonsmoker  |          1  (base)
               White#Smoker  |          1  (base)
            Black#Nonsmoker  |          1  (base)
               Black#Smoker  |   .5731579    .591634    -0.54   0.590     .0757938    4.334259
                             |
                       _cons |         .1   .0524404    -4.39   0.000     .0357788    .2794949
            ----------------------------------------------------------------------------------
            Note: _cons estimates baseline odds.
            
            
            . predict linear, xb
            
            . list id low race smoke linear if race==2 & smoke==1
            
                 +---------------------------------------+
                 |  id   low    race    smoke     linear |
                 |---------------------------------------|
             29. | 115     0   Black   Smoker   .4054651 |
             33. | 119     0   Black   Smoker   .4054651 |
             41. | 128     0   Black   Smoker   .4054651 |
             79. | 172     0   Black   Smoker   .4054651 |
            133. |  11     1   Black   Smoker   .4054651 |
                 |---------------------------------------|
            157. |  40     1   Black   Smoker   .4054651 |
            165. |  50     1   Black   Smoker   .4054651 |
            171. |  59     1   Black   Smoker   .4054651 |
            172. |  60     1   Black   Smoker   .4054651 |
            173. |  61     1   Black   Smoker   .4054651 |
                 +---------------------------------------+
            
            
            . di log(.1*.5731579*5.757576*4.545455)
            .40546526
            
            . di exp(log(.1*.5731579*5.757576*4.545455))
            1.5000002
            
            .
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Originally posted by Vilma Antonov View Post
              Thank you Bruce!

              I have used the logistic command instead of logit, and was just wondering if there is any way you can calculate the odds ratio for e.g. black smokers without having to use the logit command and calculating with the coefficients. I remember someone telling me that you could, but have not been able to find anything like it... otherwise I'll just use this method
              Vilma, have you tried my code in #4 but with logistic in place of logit? If not, give a try. Meanwhile, take a look at this:

              Code:
              . quietly logit low i.race##i.smoke if race<=2, allbase
              
              . logit, coeflegend
              
              Logistic regression                                     Number of obs =    122
                                                                      LR chi2(3)    =  15.96
                                                                      Prob > chi2   = 0.0012
              Log likelihood = -64.20707                              Pseudo R2     = 0.1106
              
              -------------------------------------------------------------------------------
                        low | Coefficient  Legend
              --------------+----------------------------------------------------------------
                       race |
                     Black  |   1.514128  _b[2.race]
                            |
                      smoke |
                    Smoker  |   1.750517  _b[1.smoke]
                            |
                 race#smoke |
              Black#Smoker  |   -.556594  _b[2.race#1.smoke]
                            |
                      _cons |  -2.302585  _b[_cons]
              -------------------------------------------------------------------------------
              
              . quietly logistic low i.race##i.smoke if race<=2, allbase
              
              . logistic, coeflegend
              
              Logistic regression                                     Number of obs =    122
                                                                      LR chi2(3)    =  15.96
                                                                      Prob > chi2   = 0.0012
              Log likelihood = -64.20707                              Pseudo R2     = 0.1106
              
              -------------------------------------------------------------------------------
                        low | Coefficient  Legend
              --------------+----------------------------------------------------------------
                       race |
                     Black  |   1.514128  _b[2.race]
                            |
                      smoke |
                    Smoker  |   1.750517  _b[1.smoke]
                            |
                 race#smoke |
              Black#Smoker  |   -.556594  _b[2.race#1.smoke]
                            |
                      _cons |  -2.302585  _b[_cons]
              -------------------------------------------------------------------------------
              Note: _cons estimates baseline odds.
              --
              Bruce Weaver
              Email: [email protected]
              Version: Stata/MP 18.5 (Windows)

              Comment

              Working...
              X