[R] Log-likelihood function
Doxastic
connect.chris at gmail.com
Wed May 2 13:30:35 CEST 2007
Thanks. I used this and it gave me the same result as the "logLik" function.
The reason I ask is the SAS output gives me a loglik = 1089. R gives me
-298.09583. Both for my reduced model. For the saturated (or complex)
model, SAS gives me an loglik = 1143. R gives me -298.1993. The problem is
these give two very different pictures about whether I can drop the
interaction. However, I think the residual deviance in the R output is
equal to G^2. So, I can just take the difference between those two. If I
do this, I get a difference with an interpretation similar to that of what
comes from SAS. So I think I'll just go with that. But who knows if I'm
right (not me)?
Thanks!
Ross Darnell wrote:
>
> Alternatively generate the log-likelihood using the sum(dpois(y,
> fitted(model), log = TRUE))
>
>
> Regards
>
> Ross Darnell
>
>
> Doxastic wrote:
>>
>> You're right. I do need to learn more. I never learned null/residual
>> deviance. I know the deviance is equivalent to an anova decompostion.
>> But I've never dealt with it seperated like this.
>>
>> I understand deviance as the difference between two model's
>> log-likelihood difference between them and the most complex. I want to
>> compare two models that are not the most complex. That is why I wanted
>> the log-likelihood.
>>
>> I am using the poisson distribution because my response is count data, so
>> the link is the log. If the deviance in R is computed by comparing the
>> fitted model against the most saturated (which would make sense). Then
>> yes, I can use that. I just picked the log-likelihood because I'm
>> comparing two models. And that's the best way. But, it's equivalent if
>> R compares the fitted to the most complex.
>>
>> I assumed the deviance print out tested the fitted model against the
>> least complex. This tests whether the current model parameters can be
>> dropped (that's what I thought the null deviance meant). I'm not sure
>> what the residaul deviance means though.
>>
>> My main concern is why the likelihood functions differed between SAS and
>> R. If anyone has encountered this or understands why, I would appreciate
>> some help.
>>
>>
>>
>> Prof Brian Ripley wrote:
>>>
>>> I think you need to learn about deviances, which R does print.
>>>
>>> Log-likelihoods are only defined up to additive constants. In this case
>>> the conventional constant differs if you view this as a Poisson or as a
>>> product-multinomial log-linear model, and R gives you the log-likelihood
>>> for a Poisson log-linear model (assuming you specified family=poisson).
>>> However, deviances and differences in log-likelihoods do not depend on
>>> which.
>>>
>>> More details and worked examples can be found in MASS (the book, see the
>>> FAQ), including other ways to fit log-linear models in R.
>>>
>>>
>>> On Tue, 1 May 2007, someone ashamed of his real name wrote:
>>>
>>>> I've computed a loglinear model on a categorical dataset. I would like
>>>> to
>>>> test whether an interaction can be dropped by comparing the
>>>> log-likelihoods
>>>> from two models(the model with the interaction vs. the model without).
>>>> Since R does not immediately print the log-likelihood when I use the
>>>> "glm"
>>>> function, I used SAS initially. After searching for an extracting
>>>> function,
>>>> I found one in R. But, the log-likelihood given by SAS is different
>>>> from
>>>> the one given by R. I'm not sure if the "logLik" function in R is
>>>> giving me
>>>> something I don't want. Or if I'm misinterpreting the SAS output. Can
>>>> anyone help?
>>>>
>>>
>>> --
>>> Brian D. Ripley, ripley at stats.ox.ac.uk
>>> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
>>> University of Oxford, Tel: +44 1865 272861 (self)
>>> 1 South Parks Road, +44 1865 272866 (PA)
>>> Oxford OX1 3TG, UK Fax: +44 1865 272595
>>>
>>> ______________________________________________
>>> R-help at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Log-likelihood-function-tf3678882.html#a10284217
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list