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
______________________________________________
R-help@r-project.org 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.