s-news
[Top] [All Lists]

Re: save likelihood from GLM model

To: fzhang <fzhang@chg.mc.duke.edu>
Subject: Re: save likelihood from GLM model
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
Date: Tue, 24 Apr 2001 07:03:06 +0100 (BST)
Cc: <s-news@lists.biostat.wustl.edu>
In-reply-to: <005801c0cc43$9e325df0$7deb0398@mc.duke.edu>
On Mon, 23 Apr 2001, fzhang wrote:

> Hi,
> I fitted a poisson model with GLM, and would like to save the likelihood or
> log-lokelihood of the model. Can anyone point out a quick way to do this?

Depends a bit what you need. If fit is glm object, deviance(fit) gives the
deviance, which is const - 2*log-likelihood.  For many purposes you don't
need the constant, since for comparison of different models this is all you
need and technically the likelihood is only defined to a constant
(depending on the sominating measure, although here counting measure is
obviously preferred).

If you really need the log-likelhood, the formula is

sum(log(dpois(y, mu) * wt))

where y is the response, nu = fitted(fit) and wt is the weights supplied
in the fit.  You can extract all these pieces from the fit if you need to,
using model.extract(model.frame(fit), ...)

-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


<Prev in Thread] Current Thread [Next in Thread>