+ All Categories
Home > Documents > Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... ·...

Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... ·...

Date post: 07-Oct-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
23
Logistic Regression STA302 F 2014 See last slide for copyright information 1
Transcript
Page 1: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Logistic Regression

STA302 F 2014

See last slide for copyright information

1

Page 2: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Binary outcomes are common and important

•  The patient survives the operation, or does not. •  The accused is convicted, or is not. •  The customer makes a purchase, or does not. •  The marriage lasts at least five years, or does not. •  The student graduates, or does not.

2

Page 3: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Logistic Regression

Dependent variable is binary (Bernoulli): 1=Yes, 0=No

Pr{Y = 1|X = x} = E(Y |X = x) = ⇡

3

Page 4: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Least Squares vs. Logistic Regression

4

Page 5: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

The logistic regression curve arises from an indirect representation of the probability of Y=1 for a given set of x values. Representing the probability of an event by

5

Page 6: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

•  If P(Y=1)=1/2, odds = .5/(1-.5) = 1 (to 1) •  If P(Y=1)=2/3, odds = 2 (to 1) •  If P(Y=1)=3/5, odds = (3/5)/(2/5) = 1.5

(to 1) •  If P(Y=1)=1/5, odds = .25 (to 1)

6

Page 7: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

The higher the probability, the greater the odds

7

Page 8: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Linear regression model for the log odds of the event Y=1

for i = 1, …, n

log

✓⇡

1� ⇡

◆= �0 + �1x1 + . . .+ �p�1xp�1

Note ⇡ is a conditional probability.

8

Page 9: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Equivalent Statements

log

✓⇡

1� ⇡

◆= �0 + �1x1 + . . .+ �p�1xp�1

1� ⇡= e�0+�1x1+...+�p�1xp�1

= e�0e�1x1 · · · e�p�1xp�1 ,

⇡ =e�0+�1x1+...+�p�1xp�1

1 + e�0+�1x1+...+�p�1xp�1.

9

Page 10: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

•  A distinctly non-linear function •  Non-linear in the betas •  So logistic regression is an example of

non-linear regression.

E(Y |x) = ⇡ =e�0+�1x1+...+�p�1xp�1

1 + e�0+�1x1+...+�p�1xp�1

10

Page 11: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

In terms of log odds, logistic regression is like regular

regression

log

✓⇡

1� ⇡

◆= �0 + �1x1 + . . .+ �p�1xp�1

11

Page 12: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

In terms of plain odds,

•  (Exponential function of) the logistic regression coefficients are odds ratios

•  For example, “Among 50 year old men, the odds of being dead before age 60 are three times as great for smokers.”

12

Page 13: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Logistic regression

•  X=1 means smoker, X=0 means non-smoker

•  Y=1 means dead, Y=0 means alive

•  Log odds of death =

•  Odds of death =

13

Page 14: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

14

Page 15: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Cancer Therapy Example

x is severity of disease 15

Page 16: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

For any given disease severity x,

16

Page 17: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

In general,

•  When xk is increased by one unit and all other independent variables are held constant, the odds of Y=1 are multiplied by

•  That is, is an odds ratio --- the ratio of the odds of Y=1 when xk is increased by one unit, to the odds of Y=1 when everything is left alone.

•  As in ordinary regression, we speak of “controlling” for the other variables.

17

Page 18: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

The conditional probability of Y=1

This formula can be used to calculate a predicted P(Y=1|x). Just replace betas by their estimates

It can also be used to calculate the probability of getting the sample data values we actually did observe, as a function of the betas.

⇡ =e�0+�1x1+...+�p�1xp�1

1 + e�0+�1x1+...+�p�1xp�1

=ex

0i�

1 + ex0i�

18

Page 19: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Likelihood Function

`(�) =nY

i=1

P (Yi = yi|xi) =nY

i=1

⇡yi(1� ⇡)1�yi

=nY

i=1

ex

0i�

1 + ex0i�

!yi 1� ex

0i�

1 + ex0i�

!1�yi

=nY

i=1

ex

0i�

1 + ex0i�

!yi ✓1

1 + ex0i�

◆1�yi

=nY

i=1

eyix0i�

1 + ex0i�

=ePn

i=1 yix0i�

Qni=1

�1 + ex

0i��

19

Page 20: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Maximum likelihood estimation •  Likelihood = Conditional probability of getting

the data values we did observe, •  As a function of the betas •  Maximize the (log) likelihood with respect to

betas. •  Maximize numerically (“Iteratively re-weighted

least squares”) •  Likelihood ratio tests play he role of F tests. •  Divide regression coefficients by estimated

standard errors to get Z-tests of H0: βj=0. •  These Z-tests are like the t-tests in ordinary

regression.

20

Page 21: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

The conditional probability of Y=1

This formula can be used to calculate a predicted P(Y=1|x). Just replace betas by their estimates

It can also be used to calculate the probability of getting the sample data values we actually did observe, as a function of the betas.

⇡i

=e�0+�1xi,1+...+�p�1xi,p�1

1 + e�0+�1xi,1+...+�p�1xi,p�1

=ex

>i �

1 + ex>i �

21

Page 22: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Likelihood Function

L(�) =nY

i=1

P (Yi = yi|xi) =nY

i=1

⇡yii (1� ⇡i)

1�yi

=nY

i=1

ex

>i �

1 + ex>i �

!yi 1� ex

>i �

1 + ex>i �

!1�yi

=nY

i=1

ex

>i �

1 + ex>i �

!yi ✓1

1 + ex>i �

◆1�yi

=nY

i=1

eyix>i �

1 + ex>i �

=ePn

i=1 yix>i �

Qni=1

⇣1 + ex

>i �⌘

22

Page 23: Logistic Regression - Department of Statistical Sciencesbrunner/oldclass/302f14/lectures/... · 2015. 8. 31. · odds of Y=1 are multiplied by • That is, is an odds ratio--- the

Copyright Information

This slide show was prepared by Jerry Brunner, Department of Statistics, University of Toronto. It is licensed under a Creative Commons Attribution - ShareAlike 3.0 Unported License. Use any part of it as you like and share the result freely. These Powerpoint slides will be available from the course website: http://www.utstat.toronto.edu/brunner/oldclass/302f14

23


Recommended