Announcement

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

  • Calculation of standard errors after predictive margins: how are they computed?

    Hello,

    I'm struggling how standard errors after -margins- are calculated, e.g. after -logit-. I am able to reproduce the productive margins themselves, but I am not able to derive the standard errors. They don't seem to be in line with the standard deviations of the predicted probabilities ... See example below
    Code:
    sysuse auto
    logit foreign price mpg weight length
    * Manually predict probabilities at various levels of weight
    generate p1500 = invlogit(_b[weight]*1500 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    generate p2000 = invlogit(_b[weight]*2000 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    generate p2500 = invlogit(_b[weight]*2500 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    generate p3000 = invlogit(_b[weight]*3000 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    generate p3500 = invlogit(_b[weight]*3500 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    generate p4000 = invlogit(_b[weight]*4000 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    generate p4500 = invlogit(_b[weight]*4500 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    generate p5000 = invlogit(_b[weight]*5000 + _b[price]*price +_b[mpg]*mpg + _b[length]*length + _b[_cons])
    * Calculating predictive margins using margins command
    margins, at ( weight =(1500(500)5000))
    And here is (part of) the output:
    Code:
    Logistic regression                             Number of obs     =         74
                                                    LR chi2(4)        =      55.94
                                                    Prob > chi2       =     0.0000
    Log likelihood = -17.064729                     Pseudo R2         =     0.6211
    
    ------------------------------------------------------------------------------
         foreign |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           price |   .0009392   .0003093     3.04   0.002      .000333    .0015454
             mpg |  -.1155925   .0966509    -1.20   0.232    -.3050248    .0738398
          weight |  -.0078002   .0030342    -2.57   0.010    -.0137471   -.0018534
          length |   .0387482   .0875022     0.44   0.658    -.1327529    .2102493
           _cons |   9.883036   11.26217     0.88   0.380    -12.19042    31.95649
    ------------------------------------------------------------------------------
    
    . * Calculating predictive margins using margins command
    . margins, at ( weight =(1500(500)5000))
    
    Predictive margins                              Number of obs     =         74
    Model VCE    : OIM
    
    Expression   : Pr(foreign), predict()
    
    1._at        : weight          =        1500
    2._at        : weight          =        2000
    3._at        : weight          =        2500
    4._at        : weight          =        3000
    5._at        : weight          =        3500
    6._at        : weight          =        4000
    7._at        : weight          =        4500
    8._at        : weight          =        5000
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |   .9978147   .0039638   251.73   0.000     .9900458    1.005584
              2  |   .9230255   .0393331    23.47   0.000     .8459341    1.000117
              3  |   .5344313   .1674495     3.19   0.001     .2062364    .8626262
              4  |   .2003275     .07624     2.63   0.009     .0508998    .3497552
              5  |   .0874817   .0298857     2.93   0.003     .0289067    .1460567
              6  |   .0129882   .0135501     0.96   0.338    -.0135694    .0395459
              7  |   .0003349   .0007068     0.47   0.636    -.0010504    .0017201
              8  |   6.82e-06   .0000234     0.29   0.771    -.0000391    .0000527
    ------------------------------------------------------------------------------
    Below is the summary of manual predictions: the means are identical to what is predicted by -margins-
    However I cannot recreate the standard error of -margins-, e.g. Std. Dev. of manual predections at
    values of weight of 2500 and 3000 are close to each other (.3565795 and .3427131), while the
    Std. Err. produced by -margins- differs a lot for these values (.1674495 and .07624 )

    Code:
    . sum p1500-p5000
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
           p1500 |         74    .9978147    .0039419   .9830204          1
           p2000 |         74    .9230255    .1224789   .5395426   .9999996
           p2500 |         74    .5344313    .3565795   .0231664   .9999796
           p3000 |         74    .2003275    .3427131   .0004798   .9989911
           p3500 |         74    .0874817    .2395264   9.71e-06    .952476
    -------------+---------------------------------------------------------
           p4000 |         74    .0129882    .0509261   1.97e-07   .2885812
           p4500 |         74    .0003349     .001379   3.98e-09   .0081432
           p5000 |         74    6.82e-06    .0000281   8.05e-11   .0001661
    Is there anyone who can help on this?

    Thanks a lot,
    MIke

  • #2
    in the manual (r.pdf) which you have available to you, there is a section on methods and formulas and a subsection on SE's - see if that has what you want

    Comment


    • #3
      Thank you for your suggestion: there is indeed a section on methods and formulas dealing with how to estimate the variance of the predicted probabilities. I assume you refer the section in the screenshot below.
      However, I'm still unable to figure out how the standard errors at different values of a covariate are calculated ...
      Click image for larger version

Name:	Standard errors margins.JPG
Views:	2
Size:	38.3 KB
ID:	1527467


      Attached Files

      Comment

      Working...
      X