Announcement

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

  • Problems with getting odds with the margins command in a logistic regression

    I am running a discrete time logistic regression analysis, and I´d like to use probabilities and odds to express my results. But probabilities and odds appear not to agree. I am going to exemplify my type of problem with the following sintax:


    cls
    clear all
    sysuse auto
    logistic foreign c.mpg c.price
    margins
    tab1 foreign
    display 22/74 //.2972973 Ok. the same result as margins


    *Lets go for the odds now. I expect 22/52 = 0.4230
    margins, expression(exp(predict(xb)))
    // but the result is 1.066307, not the expected.

    Where I am going wrong? How can I get the odds in accord with the probabilities?

    I am neophyte, so please excuse me if I am asking a very basic question. I have read the documentation but I continue being lost.

    Thanks in advance.
    Florentino














  • #2
    Florentino - If I understand your question correctly, your model is controlling for mpg and price. If you want the unadjusted odds you need to omit these control variables. In this case, the predicted probabilities and the odds meet your expectations.

    Code:
    . logistic foreign
    
    Logistic regression                             Number of obs     =         74
                                                    LR chi2(0)        =       0.00
                                                    Prob > chi2       =          .
    Log likelihood =  -45.03321                     Pseudo R2         =     0.0000
    
    ------------------------------------------------------------------------------
         foreign | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _cons |   .4230769   .1076025    -3.38   0.001     .2569985     .696479
    ------------------------------------------------------------------------------
    
    
    . margins
    Warning: prediction constant over observations.
    
    Predictive margins                              Number of obs     =         74
    Model VCE    : OIM
    
    Expression   : Pr(foreign), predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _cons |   .2972973   .0531331     5.60   0.000     .1931583    .4014363
    ------------------------------------------------------------------------------
    
    
    . margins, expression(exp(predict(xb)))
    Warning: prediction constant over observations.
    
    Predictive margins                              Number of obs     =         74
    Model VCE    : OIM
    
    Expression   : exp(predict(xb))
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _cons |   .4230769   .1076025     3.93   0.000       .21218    .6339739
    ------------------------------------------------------------------------------

    Comment


    • #3
      Thanks Alex for your answer.

      But I think the problem remains.


      sysuse auto
      logistic foreign c.mpg c.price
      margins
      margins, expression(exp(predict(xb)))

      If I am right, once, I have run my model (in this case the predictor variables are mpg and price) margins refers necessarily to that model.

      So, right or wrong, I expect margins give me the probabilities for the model, and I expect margins, expression(exp(predict(xb))) give me the odds of the event for the same model.

      So, I expect odds = p/(1-p)

      But p, provided by margins, is .2972973. So, I expect for margins, expression(exp(predict(xb))) 0.297/(1-0.297) = .422.

      But I get 0.6597 (I am running version 14).

      I think all margins asked refer to the same model with two predictors, so I expected concordance between odds and probabilities.


      In my real problem I have a model with 9 predictor variables. I am planning for ask margins with different combinations of predictors, but I feel unsecure, that I am losing something,important because I get outcomes that I don´t expect.

      Thanks again Alex for your kind answer.
      Florentino.














      Comment


      • #4
        When you use -margins-, it calculates a predicted probability, or a predicted odds as the case may be, for each observation in the data set, conditioning those calculations on whatever you specified in the -margins- command's varlist and -at()- and -atmeans- options. Then it averages those predictions over the data set. The average odds will, therefore, not equal the odds that one would calculate as p*/(1-p*) where p* is the average probability, because the transformation odds = p/(1-p) is non-linear.

        Comment


        • #5
          Florentino - I still think this is how you are interpreting your model. Interestingly, in my field (clinical epidemiology) when you add in predictors, we usually want to see the effect of these predictors on the outcome, so we would either predict odds or probabilities over levels of certain predictors, such as:

          Code:
          margins, atmeans
          
          //probabilities
          margins, at(mpg=(15(10)35))
          
          //odds
          margins, expression(exp(predict(xb))) at(mpg=(15(10)35))

          Also, in post #2 above, you can see that the constant only model reflects the odds as _cons. Once you add predictors into the model, _cons is now the odds when mpg and price are at zero (not always a realistic value.) see: http://www.ats.ucla.edu/stat/mult_pk...odds_ratio.htm). You can also see this with -margins-


          Code:
          . logistic foreign c.mpg c.price
          
          Logistic regression                             Number of obs     =         74
                                                          LR chi2(2)        =      17.14
                                                          Prob > chi2       =     0.0002
          Log likelihood = -36.462189                     Pseudo R2         =     0.1903
          
          ------------------------------------------------------------------------------
               foreign | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   mpg |   1.263436   .0848332     3.48   0.000     1.107642    1.441143
                 price |   1.000266   .0001166     2.28   0.022     1.000038    1.000495
                 _cons |   .0004769   .0009747    -3.74   0.000     8.69e-06    .0261845
          ------------------------------------------------------------------------------
          Notice that the odds below is the same as the _cons above with mpg and price ==0

          Code:
          . margins, expression(exp(predict(xb))) at(mpg=0 price=0)
          
          **[output removed]
          
          . margins, expression(exp(predict(xb))) at((zero) _all)
          
          Adjusted predictions                            Number of obs     =         74
          Model VCE    : OIM
          
          Expression   : exp(predict(xb))
          at           : mpg             =           0
                         price           =           0
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                 _cons |   .0004769   .0009747     0.49   0.625    -.0014335    .0023874
          ------------------------------------------------------------------------------
          And here, -margins- is predicting odds across observed data.

          Code:
          . margins, expression(exp(predict(xb))) asobserved
          
          **[output removed]
          
          . margins, expression(exp(predict(xb)))
          
          Predictive margins                              Number of obs     =         74
          Model VCE    : OIM
          
          Expression   : exp(predict(xb))
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                 _cons |   1.066307    .758822     1.41   0.160    -.4209567    2.553571
          ------------------------------------------------------------------------------

          Comment


          • #6
            Thanks, Clyde. I think I understand what were my wrong expectations. What you said is very clear.

            Thanks, Alex, I am understanding better now an important command, and its possibilities.

            Comment

            Working...
            X