UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Applied Logistic Regression by Hosmer and Lemeshow
Chapter 5: Assessing the Fit of the Model

This chapter makes use of the lowbwt file.
use lowbwt
In order to demonstrate the logistic regression diagnostic we need to compute the following model.
/* create dummy variable for the variable race */
xi i.race
i.race                Irace_1-3    (naturally coded; Irace_1 omitted)

/* create dichotomous variable lwd from variable lwt */
generate lwd = (lwt<110)

/* create dichotomous variable ptd from variable ptl */
generate ptd=(ptl~=0)

/* create two interaction variables */
generate agelwd=age*lwd
generate smokelwd=smoke*lwd

/* run logistic regression model */
logit low age Irace_2 Irace_3 smoke ht ui lwd ptd agelwd smokelwd

Iteration 0:   log likelihood =   -117.336
Iteration 1:   log likelihood = -97.135228
Iteration 2:   log likelihood =  -96.03855
Iteration 3:   log likelihood = -96.006202
Iteration 4:   log likelihood =  -96.00616

Logit estimates                                   Number of obs   =        189
                                                  LR chi2(10)     =      42.66
                                                  Prob > chi2     =     0.0000
Log likelihood =  -96.00616                       Pseudo R2       =     0.1818

------------------------------------------------------------------------------
     low |      Coef.   Std. Err.       z     P>|z|       [95% Conf. Interval]
---------+--------------------------------------------------------------------
     age |  -.0839782   .0455663     -1.843   0.065      -.1732864    .0053301
 Irace_2 |   1.083103   .5189153      2.087   0.037       .0660474    2.100158
 Irace_3 |   .7596787   .4640335      1.637   0.102      -.1498103    1.669168
   smoke |   1.153131   .4584383      2.515   0.012       .2546084    2.051653
      ht |   1.359216    .661471      2.055   0.040        .062757    2.655676
      ui |   .7281685   .4794797      1.519   0.129      -.2115945    1.667932
     lwd |  -1.729949   1.868306     -0.926   0.354      -5.391762    1.931863
     ptd |   1.231578   .4713903      2.613   0.009       .3076701    2.155486
  agelwd |   .1474112   .0828594      1.779   0.075      -.0149902    .3098127
smokelwd |  -1.407375   .8186761     -1.719   0.086      -3.011951    .1972003
   _cons |  -.5117544   1.087536     -0.471   0.638      -2.643286    1.619777
------------------------------------------------------------------------------
Now we will compute various diagnostic statistics.
/* predicted probability of a positive score */
/* denoted pi-hat in Hosmer and Lemeshow */
predict p
predict dx2, dx2
predict dd, ddeviance
predict db, dbeta
Figure 5.3 -- page 162
graph twoway scatter dx2 p, ylabel(0(5)15) xlabel(0 .5 1)
Figure 5.4 -- page 163
graph twoway scatter dd p, ylabel(0(2)6) xlabel(0 .5 1) 
Figure 5.5 -- page 164
graph twoway scatter db p, ylabel(0(.5)1.5) xlabel(0 .5 1)
Figure 5.6 -- page 165
graph twoway scatter dx2 p [w=db], ylabel(0(5)15) xlabel(0 .5 1) msymbol(oh)

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California