Closed linzhp closed 10 years ago
The implementation of dist_pdf for dispois could avoid such overflow. So why not use a similar implementation for dis dislnorm and disexp?
Since the Poisson distribution is discrete, avoiding the overflow was trivial (and happened by chance).
I've made some changes to the dislnorm
and disexp
which should improve the situation:
q = c(2, 1000); pars = c(-70, 2); xmin = 2
log(plnorm(q-0.5, pars[1], pars[2], lower.tail=FALSE) -
plnorm(q+0.5, pars[1], pars[2], lower.tail=FALSE)) -
plnorm(xmin-0.5, pars[1], pars[2], lower.tail=FALSE, log.p=TRUE)
##Gives [1] -0.0001196 -Inf
l1 = plnorm(q-0.5, pars[1], pars[2], lower.tail=FALSE, log.p=TRUE)
l2 = plnorm(q+0.5, pars[1], pars[2], lower.tail=FALSE, log.p=TRUE)
l1 + log(1-exp(l2-l1)) - plnorm(xmin-0.5, pars[1], pars[2], lower.tail=FALSE, log.p=TRUE)
##Gives [1] -1.196e-04 -1.238e+02
When
log=TRUE
, the underflow should be avoided. However, this line would cause an underflow regardless of thelog
option.@csgillespie Is there any alternative implementation to avoid that?