Lecture13 PDF
Lecture13 PDF
Logistic Regression
Sandy Eckel
seckel@jhsph.edu
13 May 2008
1
Logistic Regression
Basic Idea:
Logistic regression is the type of
regression we use for a response variable
(Y) that follows a binomial distribution
Linear regression is the type of regression
we use for a continuous, normally
distributed response (Y) variable
Y ~ Binomial(n,p)
n independent trials
(e.g., coin tosses)
p = probability of success on each trial
(e.g., p = ½ = Pr of heads)
Y = number of successes out of n trials
(e.g., Y= number of heads)
3
Binomial Distribution Example
y
Example:
4
Why can’t we use Linear Regression
to model binary responses?
5
Binomial Y example
6
Model
7
How do we estimate p?
Maximum Likelihood Method
The method of maximum likelihood estimation chooses
values for parameter estimates which make the observed
data “maximally likely” under the specified model
5.0e-11
MLE: p=0.63
0
0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1
p=Prob(Event) 8
Maximum Likelihood
Clinical trial example
Under the binomial model, ‘likelihood’ for observed Y=y
n y
P(Y = y ) = p (1 − p )
n− y
y
So for this example the likelihood function is:
35 22
P(Y = y ) = p (1 − p )
13
22
So, estimate p by choosing the value for p which makes
observed data “maximally likely”
i.e., choose p that makes the value of Pr (Y=22) maximal
The ML estimate of p is y/n
= 22/35
= 0.63
The estimated proportion of patients who will experience
relief is 0.63 9
Confidence Interval (CI) for p
p (1 − p ) pq
Variance of p̂ : Var( p̂)= =
n n
“Standard Error” of p̂ : pq
n
Estimate of “Standard Error” of p̂ : pˆ qˆ
n
10
Confidence Interval for p
pˆ ± 1.96
pˆ qˆ
= 0.63 ± 1.96
(0.63)(0.37)
n 35
LB: 0.63-1.96(.082)
UB: 0.63+1.96(.082)
=(0.47, 0.79)
11
Conclusion
12
Aside: Review of Probabilities and Odds
odds(Death | Vit. A)
OR =
odds(Death | No Vit A.)
14
Aside: Review of Odds Ratio Interpretation
15
Logistic Regression
Placebo
( )
( ) Drug
0
0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1
p
17
Odds Ratio
odds(Relief | Drug)
OR =
odds(Relief | Placebo)
P(Relief | Drug) / [1 - P(Relief | Drug)]
=
P(Relief | Placebo) / [1 - P(Relief | Placebo)]
0.63/(1 - 0.63)
= = 2.26
0.45/(1 - 0.45)
18
Confidence Interval for OR
1 1 1 1
se(log(Oˆ R)) = + + + = 0.489
22 13 15 20
find log( ˆ
O R ) ± 1 . 96 se (log( ˆ
O R ))
Then (eL,eU)
19
Interpretation
OR = 2.26
95% CI: (0.86 , 5.90)
20
Logistic Regression
21
A regression model for the log odds
P(relief | Tx)
log[ odds(Relief | Tx) ] = log = β + β Tx
0 1
P(no relief | Tx)
where: Tx = 0 if Placebo
1 if Drug
log( odds(Relief|Drug) ) = β0 + β1
log( odds(Relief|Placebo) ) = β0
22
And…
Because of the basic property of logs:
odds(R | D)
log =
β1
odds(R | P)
------------------------------------------------------------------------------
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
Tx | .8137752 .4889211 1.66 0.096 -.1444926 1.772043
(Intercept) | -.2876821 .341565 -0.84 0.400 -.9571372 .3817731
------------------------------------------------------------------------------
Estimates:
25
Logistic Regression
26
Logistic Regression
Thus:
Pr(Y = 1)
log = β0 + β1X1 + ... + βrXr
Pr(Y = 0)
But, why use log(odds)?
28
Transforming a proportion…
29
“Logit” transformation of the probability
Pr(Y = 1) 0 1 “probability”
Pr(Y = 1)
0 ∞ “odds”
1 − Pr(Y = 1)
Pr(Y = 1)
log -∞ ∞ “log-odds” or “logit”
1 − Pr(Y = 1)
30
Logit Function
logit function
10
5
log-odds
-5
-10
0 .5 1
Probability of Success
31
Key Relationships
32
Solve for p as a function of the coefficients
34
Example
Dependence of Blindness on Age
35
Example: Data
20 6 / 50
35 7 / 50
45 26 / 50
55 37 / 50
70 44 / 50
36
Question
37
Model 1 – Intercept only model
logit(pi) = β0*
38
Model 2 – Intercept and age
------------------------------------------------------------------------------
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
(Intercept) | -.0800427 .1265924 -0.63 0.527 -.3281593 .1680739
------------------------------------------------------------------------------
exp( −.08)
logit( p̂i) = -0.08 or pˆ i = = 0.48
1 + exp( −.08)
40
Results
------------------------------------------------------------------------------
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
age | .0940683 .0119755 7.86 0.000 .0705967 .1175399
(Intercept) | -4.356181 .5700966 -7.64 0.000 -5.473549 -3.238812
------------------------------------------------------------------------------
42
What about the Odds Ratio?
Maximum likelihood estimates:
OR = exp( β̂1)= exp(0.094)= 1.10
SE( β̂1 ) =SE(log(OR) ) = 0.013
Same z-test, reworded for OR scale:
Ho: exp(β1) = 1
z = 7.86 p-val = 0.000
95% C.I. for β1 (1.07, 1.13)
*(calculated on log scale, then exponentiated!!)
e(0.094 – 1.96*0.013), e(0.094 + 1.96*0.013)
1 Observed
Prob Blindness
.5
Predicted
0
20 40 60 80
Age
44
Model 2 fit
.5
Predicted
0
20 40 60 80
Age 45
Conclusion
46
Lecture 13 Summary
Systematic:
logit( P(Yi = 1)) = log(odds(Yi = 1)) = β 0 + β1 x1 + β 2 x2
Random:
Yi ~ Binomial (n, p ) = Binomial (1, pi )