OLS vs Logistic Scatterplots

Logistic regression models (also known as logit models) provide one approach to analyzing binary response variables. The goal in logistic regression is to model Pr(y=1 | x) = F(xβ). To do this we will make use of the logit transformation.
.
Let odds = P/(1-P)
.
Let log odds or logit g(x) = ln(P/(1-P)) 
= xβ. In the case of simple logistic regression,
i.e., with a single predictor,
g(x) = β0 + β1x.
Thus, π(x) can be written

This can be shown to be true since exp(xβ)
are just the odds,
The coefficients for logistic regression are estimated using maximum likelihood. Unlike least squares regression, in which, the coefficients can be estimated in a single pass, the coefficients for logistic regression are estimated through an iterative procedure. This is because the effects in OLS regression are linear while logistic regression the solutions are nonlinear in β0 and β1 The goal is to find the coefficients that make the data most likely. This is done by maximizing the likelihood function,


Thus, the odds would be exp(xb) = exp(β0 + β1x)
which can be
rewritten as exp(β0)exp(β1x).
If we increase x by one we get exp(β0 + β1(x+1)) = exp(β0 + β1x+β1)
which, in turn, can be rewritten as exp(β0)exp(β1x)exp(β1).
Next, to compare the odds before and after adding one to x, we compute the odds ratio,
exp(β0)exp(β1x)exp(β1)
---------------------------------- = exp(β1),
exp(β0)exp(β1x)
that is, the odds ratio for a one unit change is just the exponentiated log odds coefficient.
Before we begin estimating some logit models let's play with the grlog command (findit grlog) to see how changes in the constant and logistic regression coefficient affect the predicted probabilities. Now let's begin with some very simple examples.
Intercept Only Example
use http://www.gseis.ucla.edu/courses/data/honors
describe
Contains data from http://www.gseis.ucla.edu/courses/data/honors.dta
obs: 200
vars: 7 10 Feb 2001 16:27
size: 6,400 (99.8% of memory free)
-------------------------------------------------------------------------------
1. id float %9.0g
2. female float %9.0g fl
3. ses float %9.0g sl
4. lang float %9.0g language test score
5. math float %9.0g math score
6. science float %9.0g science score
7. honors float %9.0g
-------------------------------------------------------------------------------
summarize
Variable | Obs Mean Std. Dev. Min Max
---------+-----------------------------------------------------
id | 200 100.5 57.87918 1 200
female | 200 .545 .4992205 0 1
ses | 200 2.055 .7242914 1 3
lang | 200 52.23 10.25294 28 76
math | 200 52.645 9.368448 33 75
science | 200 51.85 9.900891 26 74
honors | 200 .265 .4424407 0 1
tabulate honors
-> tabulation of honors
honors | Freq. Percent Cum.
------------+-----------------------------------
0 | 147 73.50 73.50
1 | 53 26.50 100.00
------------+-----------------------------------
Total | 200 100.00
logit honors
Logit estimates Number of obs = 200
LR chi2(0) = -0.00
Prob > chi2 = .
Log likelihood = -115.64441 Pseudo R2 = -0.0000
------------------------------------------------------------------------------
honors | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | -1.020141 .1602206 -6.37 0.000 -1.334167 -.706114
------------------------------------------------------------------------------
display ln(.265/(1-.265))
-1.0201407
predict pr0
list id hon pr0 in 1/10
+---------------------+
| id honors pr0 |
|---------------------|
1. | 8 0 .265 |
2. | 67 0 .265 |
3. | 165 0 .265 |
4. | 173 1 .265 |
5. | 135 1 .265 |
|---------------------|
6. | 5 0 .265 |
7. | 89 0 .265 |
8. | 46 0 .265 |
9. | 111 0 .265 |
10. | 19 0 .265 |
|---------------------|
predict xb, xb
list id honors xb
+--------------------------+
| id honors xb |
|--------------------------|
1. | 8 0 -1.020141 |
2. | 67 0 -1.020141 |
3. | 165 0 -1.020141 |
4. | 173 1 -1.020141 |
5. | 135 1 -1.020141 |
|--------------------------|
6. | 5 0 -1.020141 |
7. | 89 0 -1.020141 |
8. | 46 0 -1.020141 |
9. | 111 0 -1.020141 |
10. | 19 0 -1.020141 |
|--------------------------|
Dichotomous Predictor Example
codebook female
-------------------------------------------------------------------------------------------------
female (unlabeled)
-------------------------------------------------------------------------------------------------
type: numeric (float)
label: fl
range: [0,1] units: 1
unique values: 2 missing .: 0/200
tabulation: Freq. Numeric Label
91 0 male
109 1 female
tabulate honors female, cell nofreq
| female
honors | male female | Total
-----------+----------------------+----------
0 | 36.50 37.00 | 73.50
1 | 9.00 17.50 | 26.50
-----------+----------------------+----------
Total | 45.50 54.50 | 100.00
display 36.5*17.5/(37*9)
1.9181682
logit honors female
Logit estimates Number of obs = 200
LR chi2(1) = 3.94
Prob > chi2 = 0.0473
Log likelihood = -113.6769 Pseudo R2 = 0.0170
------------------------------------------------------------------------------
honors | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
female | .6513707 .3336752 1.95 0.051 -.0026207 1.305362
_cons | -1.400088 .2631619 -5.32 0.000 -1.915876 -.8842998
------------------------------------------------------------------------------
logit, or
Logit estimates Number of obs = 200
LR chi2(1) = 3.94
Prob > chi2 = 0.0473
Log likelihood = -113.6769 Pseudo R2 = 0.0170
------------------------------------------------------------------------------
honors | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
female | 1.918168 .6400451 1.95 0.051 .9973827 3.689024
------------------------------------------------------------------------------
/* predicted probability for males */
display exp(-1.400088+0*.6513707)/(1+exp(-1.400088+0*.6513707))
.19780215
/* predicted probability for females */
display exp(-1.400088+1*.6513707)/(1+exp(-1.400088+1*.6513707))
.32110086
predict pr1
tablist female pr1 /* findit tablist */
+--------------------------+
| female pr1 Freq |
|--------------------------|
| female .3211009 109 |
| male .1978022 91 |
+--------------------------+
tabstat honors, by(female)
Summary for variables: honors
by categories of: female
female | mean
-------+----------
male | .1978022
female | .3211009
-------+----------
Total | .265
------------------
display ln(.1978022/(1-.1978022))
-1.4000877
display ln((.3211009/(1-.3211009))/(.1978022/(1-.1978022)))
.65137056
display (.3211009/(1-.3211009))/(.1978022/(1-.1978022))
1.918168
Continuous Predictor Example
correlate honors math
(obs=200)
| honors math
-------------+------------------
honors | 1.0000
math | 0.5417 1.0000
scatter honors math, jitter(2)
logit honors math
Logit estimates Number of obs = 200
LR chi2(1) = 65.27
Prob > chi2 = 0.0000
Log likelihood = -83.008708 Pseudo R2 = 0.2822
------------------------------------------------------------------------------
honors | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
math | .1715239 .0268555 6.39 0.000 .118888 .2241597
_cons | -10.51268 1.545072 -6.80 0.000 -13.54097 -7.484394
------------------------------------------------------------------------------
logit, or
Logit estimates Number of obs = 200
LR chi2(1) = 65.27
Prob > chi2 = 0.0000
Log likelihood = -83.008708 Pseudo R2 = 0.2822
------------------------------------------------------------------------------
honors | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
math | 1.187112 .0318805 6.39 0.000 1.126244 1.251271
------------------------------------------------------------------------------
/* predicted probability for math = 50 */
display exp(-10.51268+50*.1715239)/(1+exp(-10.51268+50*.1715239 ))
.12603452
predict pr2
tablist math pr2, sort(v)
+------------------------+
| math pr2 Freq |
|------------------------|
| 33 .0077492 1 |
| 35 .0108859 1 |
| 37 .0152727 1 |
| 38 .0180788 2 |
| 39 .0213892 6 |
|------------------------|
| 40 .0252901 10 |
| 41 .0298808 7 |
| 42 .0352747 7 |
| 43 .0416004 7 |
| 44 .049003 4 |
|------------------------|
| 45 .0576435 8 |
| 46 .0676991 8 |
| 47 .0793612 3 |
| 48 .0928321 5 |
| 49 .1083207 10 |
|------------------------|
| 50 .1260343 7 |
| 51 .1461699 8 |
| 52 .1689006 6 |
| 53 .1943615 7 |
| 54 .2226324 10 |
|------------------------|
| 55 .2537204 5 |
| 56 .2875437 7 |
| 57 .3239189 13 |
| 58 .3625541 6 |
| 59 .4030502 2 |
|------------------------|
| 60 .4449125 5 |
| 61 .4875715 7 |
| 62 .5304123 4 |
| 63 .5728096 5 |
| 64 .6141635 5 |
|------------------------|
| 65 .6539327 3 |
| 66 .6916608 4 |
| 67 .7269929 2 |
| 68 .7596831 1 |
| 69 .7895918 2 |
|------------------------|
| 70 .8166765 1 |
| 71 .8409768 4 |
| 72 .8625981 3 |
| 73 .8816931 1 |
| 75 .9130621 2 |
+------------------------+
scatter pr2 math, jitter(2)

Dichotmous & Continuous Predictors
logit honors female math
Logit estimates Number of obs = 200
LR chi2(2) = 72.83
Prob > chi2 = 0.0000
Log likelihood = -79.23169 Pseudo R2 = 0.3149
------------------------------------------------------------------------------
honors | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
female | 1.120847 .4240297 2.64 0.008 .2897644 1.95193
math | .182538 .0284206 6.42 0.000 .1268347 .2382413
_cons | -11.79228 1.718901 -6.86 0.000 -15.16127 -8.423297
------------------------------------------------------------------------------
logit, or
Logit estimates Number of obs = 200
LR chi2(2) = 72.83
Prob > chi2 = 0.0000
Log likelihood = -79.23169 Pseudo R2 = 0.3149
------------------------------------------------------------------------------
honors | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
female | 3.067452 1.300691 2.64 0.008 1.336113 7.042269
math | 1.20026 .0341121 6.42 0.000 1.135229 1.269015
------------------------------------------------------------------------------
predict pr3
scatter pr3 math
table math female, cont(mean pr3)
------------------------------
math | female
score | male female
----------+-------------------
33 | .0094928
35 | .0044808
37 | .0195023
38 | .0077227 .0233167
39 | .0092549 .0278561
40 | .0110878 .033249
41 | .0132787 .0396435
42 | .0158956 .0472077
43 | .0190184 .0561309
44 | .0227404 .0666227
45 | .0271706 .0789118
46 | .0324353 .0932411
47 | .0386795 .1098622
48 | .0460686 .1290245
49 | .0547889 .1509623
50 | .0650472 .1758769
51 | .0770696 .2039158
52 | .0910975 .2351493
53 | .269547
54 | .1261727 .3069571
55 | .1477078 .3470921
56 | .1721942 .3895253
57 | .1997884 .4337002
58 | .2305728 .4789544
59 | .2645327
60 | .3015341 .5697531
61 | .3413092 .6138161
62 | .3834506 .6560904
63 | .427419 .6960288
64 | .4725647 .733215
65 | .7673725
66 | .563462 .7983593
67 | .8261538
68 | .6502869
69 | .8725489
70 | .7281737
71 | .7627678 .907942
72 | .9221051
73 | .8224434
75 | .8696725
------------------------------
Categorical Data Analysis Course
Phil Ender