s-news
[Top] [All Lists]

Re: Deviance in a glm(family=poisson)

To: Kypreos Theodore <vamos@x-treme.gr>
Subject: Re: Deviance in a glm(family=poisson)
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Tue, 26 Jun 2001 10:49:15 +0100 (BST)
Cc: <s-news@wubios.wustl.edu>
In-reply-to: <000e01c0fe1c$650f1300$33f5cdd4@ATH.FORTHNET.GR>
On Tue, 26 Jun 2001, Kypreos Theodore wrote:

> I want to ask something about the deviance in a glm(family=poisson)
> As we know, when we want to compute the Deviance, we have to  compute
something like that:
>
> Dos = 2*Sum{y(i)*log(y(i)/mu(i) - (y(i)-mu(i))}
>
> What happens when in the response variable (y), is there a value equal to
zero y=0 ) ( this is possible as y="counts"). log(zero)=- inf. So,
what should be done, to compute the Deviance and how S-plus computes it?

0*log(0) = 0.

One great thing about S is that you can read the source code, and you
could have checked for yourself by

> poisson()$deviance
function(mu, y, w, residuals = F)
{
        nz <- y > 0
        devi <-  - (y - mu)
        devi[nz] <- devi[nz] + y[nz] * log(y[nz]/mu[nz])
        if(residuals)
                sign(y - mu) * sqrt(2 * abs(devi) * w)
        else 2 * sum(w * devi)
}

Note the need to include weights.



-- 
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>