L 83
L 83
= =
= =
=
observed is 0 y if ) | 1 Pr( 1
observed is 1 y if ) | 1 Pr(
i
i
i i
i i
i
x y
x y
p
If the observations are independent, the likelihood equation is
[
=
=
N
i
i
p L
1
) ( X y, |
The likelihood tends to be an incredibly small number, and it is generally easier to work with the
log likelihood. Ergo, taking logs, we obtain the log likelihood equation:
=
=
N
i
i
p L
1
ln ) ( ln X y, |
Before proceeding, lets see how this works in practice! Here is how you compute p
i
and the log
of p
i
using Stata:
. quietly logit grade gpa tuce psi
. * Compute probability that y = 1
. predict pi
(option p assumed; Pr(grade))
. * If y = 0, replace pi with probability y = 0
. replace pi = 1 - pi if grade == 0
(21 real changes made)
. * compute log of pi
. gen lnpi = ln(pi)
. list grade pi lnpi, sep(8)
+------------------------------+
| grade pi lnpi |
|------------------------------|
1. | 0 .9386242 -.0633401 |
2. | 1 .1110308 -2.197947 |
3. | 0 .9755296 -.0247748 |
| --- Output deleted --- |
30. | 1 .569893 -.5623066 |
31. | 1 .9453403 -.0562103 |
32. | 1 .6935114 -.3659876 |
+------------------------------+
So, this tells us that the predicted probability of the first case being 0 was .9386. The probability
of the second case being a 1 was .111. The probability of the 3
rd
case being a 0 was .9755; and
so on. The likelihood is therefore
Logistic Regression, Part IIIPage 16
2524 00000 . 6935 . * ... * 9755 . * 1110 . * 9386 . ) (
1
= = =
[
=
N
i
i
p L X y, |
which is a really small number; indeed so small that your computer or calculator may have
trouble calculating it correctly (and this is only 32 cases; imagine the difficulty if you have
hundreds of thousands). Much easier to calculate is the log likelihood, which is
88963 . 12 366 . ... 198 . 2 0633 . ln ) ( ln
1
= + + + = =
=
N
i
i
p L X y, |
Statas total command makes this calculation easy for us:
. total lnpi
Total estimation Number of obs = 32
--------------------------------------------------------------
| Total Std. Err. [95% Conf. Interval]
-------------+------------------------------------------------
lnpi | -12.88963 3.127734 -19.26869 -6.510578
--------------------------------------------------------------
Note: The maximum likelihood estimates are those values of the parameters that make the
observed data most likely. That is, the maximum likelihood estimates will be those values which
produce the largest value for the likelihood equation (i.e. get it as close to 1 as possible; which is
equivalent to getting the log likelihood equation as close to 0 as possible).