Lecture 10 PDF
Lecture 10 PDF
Example: 8
7
1
1
1
0
Admissions Data 5
3
1
1
1
0
3 1 0
5 1 1
20 observations of 7 1 1
exp( Xβ )
Formula to back out Y from logit estimates: Y = 1 + exp( Xβ )
.dis exp(_b[gender]+_b[_cons])/(1+exp(_b[gender]+_b[_cons]))
.7
. dis exp(_b[_cons])/(1+exp(_b[_cons]))
.3
Ex. 1: Categorical Independent Variable
To get the results in terms of odds ratios:
logit admit gender, or
------------------------------------------------------------------------------
admit | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
gender | 5.444444 5.313234 1.736 0.082 .8040183 36.86729
------------------------------------------------------------------------------
------------------------------------------------------------------------------
admit | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
gender | 5.444444 5.313234 1.736 0.082 .8040183 36.86729
------------------------------------------------------------------------------
------------------------------------------------------------------------------
admit | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
apt | 2.574129 1.088527 2.236 0.025 1.123779 5.8963
------------------------------------------------------------------------------
0 2 4 6 8 10
aptitude
. predict p
. line p aptitude, sort
Ex. 2: Continuous Independent Var.
1
.8 .6
Pr(admit)
50% chance of
.4
being admitted
.2
0
0 2 4 6 8 10
aptitude
. predict p
. line p aptitude, sort
Example 3: Categorical & Continuous
Independent Variables
logit admit gender apt
Logit estimates Number of obs = 20
LR chi2(2) = 9.16
Prob > chi2 = 0.0102
Log likelihood = -9.2820991 Pseudo R2 = 0.3304
------------------------------------------------------------------------------
admit | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
gender | .2671938 1.300899 0.205 0.837 -2.282521 2.816909
apt | .8982803 .4713791 1.906 0.057 -.0256057 1.822166
_cons | -4.028765 1.838354 -2.192 0.028 -7.631871 -.4256579
------------------------------------------------------------------------------
tabulate honors
honors | Freq. Percent Cum.
------------+-----------------------------------
0 | 147 73.50 73.50
1 | 53 26.50 100.00
------------+-----------------------------------
Total | 200 100.00
Example 4: Categorical and continuous
independent variables
generate honors = (write>=60)
tabulate honors
honors | Freq. Percent Cum.
------------+-----------------------------------
0 | 147 73.50 73.50
1 | 53 26.50 100.00
------------+-----------------------------------
Total | 200 100.00
Example 4: Categorical and continuous independent var.
describe honors female ses1 ses2 read math
tab1 honors female ses1 ses2 read math -> tabulation of ses1
-> tabulation of honors ses==low | Freq. Percent Cum.
------------+-----------------------------------
honors | Freq. Percent Cum. 0 | 153 76.50 76.50
------------+----------------------------------- 1 | 47 23.50 100.00
0 | 147 73.50 73.50 ------------+-----------------------------------
1 | 53 26.50 100.00 Total | 200 100.00
------------+-----------------------------------
Total | 200 100.00
-> tabulation of ses2
-> tabulation of female
ses==middle | Freq. Percent Cum.
female | Freq. Percent Cum. ------------+-----------------------------------
------------+----------------------------------- 0 | 105 52.50 52.50
male | 91 45.50 45.50 1 | 95 47.50 100.00
female | 109 54.50 100.00 ------------+-----------------------------------
------------+----------------------------------- Total | 200 100.00
Total | 200 100.00
Example 4: Categorical and continuous
independent var.
We would
.04
normally worry
.03
Density
.04
0
30 40 50 60 70 80
reading score
.03
Density
.02
.01
0
30 40 50 60 70
math score
Example 4: Categorical and continuous
independent var.
We would normally
.04
but….
.02.01
.04
0
30 40 50 60 70 80
reading score
.03
Density
.02
30 40 50 60 70
math score
Example 4: Categorical and continuous
independent variables
logit honors female ses1 ses2 read math
------------------------------------------------------------------------------
honors | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
female | 1.145726 .4513589 2.538 0.011 .2610792 2.030374
ses1 | -.0541296 .5945439 -0.091 0.927 -1.219414 1.111155
ses2 | -1.094532 .4833959 -2.264 0.024 -2.04197 -.1470932
read | .0687277 .0287044 2.394 0.017 .0124681 .1249873
math | .1358904 .0336874 4.034 0.000 .0698642 .2019166
_cons | -12.49919 1.926421 -6.488 0.000 -16.27491 -8.723475
------------------------------------------------------------------------------
Logit estimates
Same as logit, or Number of obs
LR chi2(5)
=
=
200
87.30
Prob > chi2 = 0.0000
Log likelihood = -71.994756 Pseudo R2 = 0.3774
------------------------------------------------------------------------------
honors | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
female | 3.144725 1.4194 2.538 0.011 1.29833 7.616932
ses1 | .9473093 .563217 -0.091 0.927 .2954031 3.037865
ses2 | .3346963 .1617908 -2.264 0.024 .1297728 .8632135
read | 1.071145 .0307466 2.394 0.017 1.012546 1.133134
math | 1.145556 .0385909 4.034 0.000 1.072363 1.223746
-------------------------------------------------------------------------------
30 40 50 60 70 80
Reading Score
Graphing the Results
Can do this separately for males & females
Impact of Reading Score on Probability of Honors
.6
Probability of Honors
.2 0 .4
30 40 50 60 70 80
Reading Score
Marginal impact is
Probability of Honors
30 40 50 60 70 80
Reading Score
lroc
Logistic model for honors
number of observations = 200
area under ROC curve = 0.8912
Example 4: Categorical and continuous
independent variables
1.00
function to
directly plot the
0.50
sensitivity and
0.25
specificity
as your cutoff
0.00
No honors
0
0 .2 .4 .6 .8 1
Pr(honors)
High residual
Large
Residuals points were
predicted to be
20
60
honors anyway
10
0
0 .2 .4 .6 .8 1
Pr(honors)
83
Large Same pattern
Residuals as before.
6
60
Same two
H-L dD
4
points as
outliers
2
0
0 .2 .4 .6 .8 1
Pr(honors)
83 Different points
have large
.3
62
influence.
Pregibon's dbeta
60
.2
Could eliminate
these and see if
results change.
.1
0
0 .2 .4 .6 .8 1
Pr(honors)
One way to
30
show both
25
residuals and
influence on
H-L dX^2
20
one graph is to
15
weight each
10
residual marker
by the value of
5
its influence.
0
0 .2 .4 .6 .8 1
Pr(honors)
------------------------------------------------------------------------------
prog | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
general |
female | -.0840263 .3806826 -0.22 0.825 -.8301505 .6620979
math | -.0739045 .0254512 -2.90 0.004 -.1237879 -.0240211
socst | -.0370939 .0217034 -1.71 0.087 -.0796319 .0054441
_cons | 5.130723 1.392646 3.68 0.000 2.401188 7.860258
-------------+----------------------------------------------------------------
vocation |
female | -.0177488 .4085162 -0.04 0.965 -.8184258 .7829282
math | -.1127775 .0289322 -3.90 0.000 -.1694836 -.0560714
socst | -.079675 .0227946 -3.50 0.000 -.1243516 -.0349984
_cons | 9.106635 1.545711 5.89 0.000 6.077098 12.13617
------------------------------------------------------------------------------
(Outcome prog==academic is the comparison group)
Multinomial Logit Example
. mlogit, rrr
------------------------------------------------------------------------------
prog | RRR Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
general |
female | .9194071 .3500023 -0.22 0.825 .4359837 1.938856
math | .9287604 .023638 -2.90 0.004 .8835673 .9762651
socst | .9635856 .0209131 -1.71 0.087 .9234562 1.005459
-------------+----------------------------------------------------------------
vocation |
female | .9824078 .4013295 -0.04 0.965 .4411255 2.18787
math | .8933494 .0258466 -3.90 0.000 .8441006 .9454716
socst | .9234164 .0210489 -3.50 0.000 .8830693 .9656069
------------------------------------------------------------------------------
(Outcome prog==academic is the comparison group)
Odds comparing|
Group 1 vs Group 2| b z P>|z| e^b e^bStdX
------------------+---------------------------------------------
general -vocation | -0.06628 -0.155 0.877 0.9359 0.9675
general -academic | -0.08403 -0.221 0.825 0.9194 0.9589
vocation-general | 0.06628 0.155 0.877 1.0685 1.0336
vocation-academic | -0.01775 -0.043 0.965 0.9824 0.9912
academic-general | 0.08403 0.221 0.825 1.0877 1.0428
academic-vocation | 0.01775 0.043 0.965 1.0179 1.0089
----------------------------------------------------------------
female
Avg|Chg| general vocation academic
0->1 .0101265 -.01518974 .00147069 .01371908
math
Avg|Chg| general vocation academic
Min->Max .49023263 -.23754089 -.49780805 .73534894
-+1/2 .01500345 -.0083954 -.01410978 .02250516
-+sd/2 .13860906 -.07673311 -.13118048 .20791358
MargEfct .01500588 -.00839781 -.01411102 .02250882
(socst omitted)
female-0/1 G VA
math-std V G A
socst-std V G A
-.13 -. 09 -.05 0 .04 .08 .12 .17 .21
C hange in Predicted Probability for prog
female G
V
0/1 A
math V
G
Std Coef A
socst V
G
Std Coef A
-1.06 -.92 -.79 -.66 -.53 -.4 -.26 -.13 0
Logit Coefficient Scale Relative to C ategory academic
(output omitted)
------------------------------------------------------------------------------
prog | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
general |
math | -.1352046 .0305449 -4.43 0.000 -.1950716 -.0753376
science | .0602744 .0254395 2.37 0.018 .0104139 .1101348
_cons | 3.166452 1.298818 2.44 0.015 .6208165 5.712088
-------------+----------------------------------------------------------------
vocation |
math | -.1690188 .0331945 -5.09 0.000 -.2340789 -.1039588
science | .0170098 .0250403 0.68 0.497 -.0320684 .0660879
_cons | 7.053851 1.37717 5.12 0.000 4.354647 9.753055
------------------------------------------------------------------------------
(Outcome prog==academic is the comparison group)
20 40 60 80
Changing value of math