[R] accessing log likelihood of poison model
Renaud Lancelot
renaud.lancelot at cirad.fr
Sun Apr 18 08:16:19 CEST 2004
Eric Cheney wrote:
> On Sunday, 18 April 2004 at 0:52:19 +0200, Peter Dalgaard wrote:
>
>>Eric Cheney <cheney at soc.umass.edu> writes:
>>
>>
>>>Could someone tell me how to access the log likelihood
>>>of a poisson model? I've done the following....
>>>
>>><BEGIN R STUFF>
>>>
>>>freq.mod <- glm(formula = nfix ~ gls.gls + pol.gls + pol.rel + rac.gls +
>>>rac.pol + rac.rac + rac.rel + white + gls.gls.w + pol.gls.w + pol.rel.w
>>>+ rac.gls.w + rac.pol.w + rac.rac.w + rac.rac.w + rac.rel.w, family =
>>>poisson, data = Complex2.freq, offset = lnoffset)
>>>
>>>summary(freq.mod)
>>>anova(freq.mod)
>>>
>>><END R STUFF>
>>>
>>>And that's great; but I need the log likelihood.
>>>
>>>Anyone know?
>>
>>The deviance will not suffice?
>>
>> sum(dpois(nfix, fitted(freq.mod), log.p=T))
>>
>>should do the trick otherwise.
>
>
> Thank you, that did the trick. I should note that the method doesn't
> work when I have a noninteger in Y. I'm doing a "log linear" analysis
> of a cross table, and one of the cells of the cross table has a zero
> value. I put a .5 in that cell. With the ".5 analysis" the above
> method doesn't work. So I had to revert to an analysis with a zero
> cell to make it work. Which has some problems. So I'm still left
> looking for the log likelihood of the ".5 analysis". I've had success
> with Stata using this method, but not R.
>
> Thanks again.
?logLik
example from ?glm:
> counts <- c(18,17,15,20,10,20,25,13,12)
> outcome <- gl(3,1,9)
> treatment <- gl(3,3)
> print(d.AD <- data.frame(treatment, outcome, counts))
treatment outcome counts
1 1 1 18
2 1 2 17
3 1 3 15
4 2 1 20
5 2 2 10
6 2 3 20
7 3 1 25
8 3 2 13
9 3 3 12
> glm.D93 <- glm(counts ~ outcome + treatment, family=poisson())
>
> logLik(glm.D93)
`log Lik.' -23.38066 (df=5)
Best,
Renaud
--
Dr Renaud Lancelot, vétérinaire
C/0 Ambassade de France - SCAC
BP 834 Antananarivo 101 - Madagascar
e-mail: renaud.lancelot at cirad.fr
tel.: +261 32 04 824 55 (cell)
+261 20 22 665 36 ext. 225 (work)
+261 20 22 494 37 (home)
More information about the R-help
mailing list