[R] Poisson dpois value is too small for double precision thus corrupts loglikelihood

Duncan Murdoch murdoch at stats.uwo.ca
Tue Oct 27 01:29:54 CET 2009


On 26/10/2009 8:21 PM, R_help Help wrote:
> Hi - I have a likelihood function that involves sums of two possions:
> 
> L = a*dpois(Xi,theta1)*dpois(Yi,theta2)+b*(1-c)*a*dpois(Xi,theta1+theta3)*dpois(Yi,theta2)
> 
> where a,b,c,theta1,theta2,theta3 are parameters to be estimated.
> (Xi,Yi) are observations. However, Xi and Yi are usually big (>
> 20000). This causes dpois to returns 0 depending on values of theta1,
> theta2 and theta3.
> 
> My first question is: is there anyway around this?
> 
> My second question is regarding the likelihood function value. Since
> dpois returns 0, my log likelihood becomes infinite and causes problem
> when optimization. Is there any smart way to avoid this?

If you use log=TRUE, you'll get the log density instead of the density, 
and you won't get underflow.

Finding the sum of terms whose log you know but whose value you can't 
represent is just a little tricky, but you can do it using identities like

log(A + B) = log(A) + log(1 + B/A)
            = log(A) + log(1 + exp(log(B) - log(A)))

Duncan Murdoch




More information about the R-help mailing list