Logistic Nota
Logistic Nota
Logistic Nota
LOGISTIC REGRESSION
3.
4.
1. Binary outcome..
Binary outcomes are outcomes with two possible values, Success
or failure
i 1, 2,..., n
yi 0 j xij i xi i
j 1
yi 0 or 1
k
P ( yi 1) i with 0 i 1
P ( yi 0) 1 i
E ( yi ) i xi i
Var ( yi ) i (1 i )
2
yi
0 E ( yi ) i xi i 1
Nonsensical predictions.
Bad predictions due to nonlinear functional form even within
reasonable values of y.
10
At Least One
O-ring Failure
Temperature
at Launch
1.0
At Least One
O-ring Failure
53
70
56
70
57
72
63
73
66
75
67
75
67
76
67
76
68
78
69
79
70
80
70
81
O-Ring Fail
Temperature
at Launch
0.5
0.0
50
60
70
Temperature
80
exp(x
1
E ( y)
1 exp(x 1 exp(x
12
13
Probability
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0.0
9 10 11 12 13 14 15 16 17 18 19 20 21
Assumption
pii
P
(pi )
Logit
Transform
Predictor
Predictor
x and E ( y )
Define
ln
16
yi E ( yi ) i
where
E ( yi ) i
exp(xi
1 exp( xi
fi ( yi ) iyi (1 i )1 yi , i 1, 2,..., n
The likelihood function is
n
i 1
L(y , f i ( yi ) iyi (1 i )1 yi
We usually work with the log-likelihood:
i n
ln L(y, ln fi ( yi ) yi ln
ln(1 i )
i 1
i 1
1 i i 1
n
18
log-likelihood as
ni
ln L(y,
X y
exp(xixi
i 1 1 exp( xi
n
Xy ni i xi
i 1
Xy X because i ni i )
20
score equations
X(y 0
easy, because
ni
, i 1, 2,..., n
1 exp(xi
( x)
( x) ln
0 1 x
1 ( x)
The log-odds at x + 1 is
( x 1)
( x 1) ln
0 1 ( x 1)
1 ( x 1)
( x 1) ( x) 1
24
Odds x 1
1
OR
e
Odds x
The odds ratio is interpreted as the estimated increase in
25
Then
Then
i i xi i
Note: ( x) p
p
e x
1 p
e x
p
1 e x
x
e
Or, predicted p, p
1 e x
L( FM )
LR 2 ln
2[ln L( FM ) ln L( RM )]
L( RM )
27
For large samples, when the reduced model is correct, the test
statistic LR follows a chi-square distribution with df equal to the
difference in the no of parameters between full & reduced models.
2
If LR > ,df , we would reject the claim that the reduced model is
appropriate.
28
n
n
p i
1 e xi
'
yi
ni yi
L(saturated model)
D 2 ln
2 yi ln(
) (ni yi ) ln(
)
L(FM)
n
p
n
(1
p
)
i 1
i i
i
i
29
n y
) 0.
n(1 p)
y
) 0 if y 0 and if
np
When the logistic regression model is an adequate fit to the data, & the sample
size is large, the deviance has a chi-square distribution with n-p df; p is no of
parameters in the model.
Small values of deviance (or large p value) imply that the model provides a
satisfactory fit to the data, while large values of deviance imply that the current
model is not adequate.
31
32
If the fitted logistic regression model is correct, the HL statistic follows a chisquare distribution with g-2 df when the sample size is large.
Large values of the HL imply that the model is not adequate fit to the data.
It is also useful to compute the ratio of the HL to the no of df g-p with values
close to unity implying an adequate fit.
H null : model is not adequate
H 1 : model is adequate
33
inference
Uses the result that the MLEs have an approximate normal
distribution, so the distribution of
Z0
se( )
is standard normal if the true value of the parameter is zero. Some
computer programs report the square of Z (which is chi-square), and
others calculate the P-value using the t distribution
35
e
( x)
0 1 x
1 e
= 0 P(Presence) is the same at each level of x
> 0 P(Presence) increases as x increases
2
T .S . : X obs
2
R.R. : X obs
^
^1
^
1
2 ,1
2
P val : P ( 2 X obs
)
Odds Ratio
Interpretation of Regression Coefficient ():
In linear regression, the slope coefficient is the change in the mean response
as x increases by 1 unit
In logistic regression, we can show that:
odds( x 1)
e
odds( x)
( x)
odds( x)
1 ( x)
^
^
^
^
^
^
1.96 , 1.96
1.96
^
Step 2: Raise e = 2.718 to the lower and upper bounds of the CI:
e 1.96 , e 1.96
^ ^
^ ^
females
1
3
7
18
22
41
52
79
male
0
1
3
4
33
80
158
365
more clearly.
is highly variable, andthis
an experiment
was set up to see whether
population density was involved in determining the fraction of
males.
Density
1
4
10
22
55
121
210
444
females
1
3
7
18
22
41
52
79
male
0
1
3
4
33
80
158
365
Density
1
4
10
22
55
121
210
444
females
1
3
7
18
22
41
52
79
male
0
1
3
4
33
80
158
365
Intercept
slope
If residual deviance > residual d.o.f , we
called overdispersion
Measure of Fit
The deviance shows how well the model fits the data
Comparing two models deviances
Use a likelihood ratio test
Compare using Chi-square distribution
Model checking..
Plot the model
> par(mfrow=c(2,2))
> plot(model)
EXAMPLE 2:
Challenger Data
53
70
56
70
57
72
63
73
66
75
67
75
67
76
67
76
68
78
69
79
70
80
70
81
Chi-Square
DF
Pearson
14.049
15
0.522
Deviance
15.759
15
0.398
Hosmer-Lemeshow
11.834
0.159
exp(10.875 0.17132 x)
y
1 exp(10.875 0.17132 x)
68
69
72
73
74
75
76
77
78
Diagnostic Checking
79
80
81
82
model.
least squares estimates minimize (observed expected)2, and the logit of the