dppois.RdEvaluates the difference between two Poisson cumulative distribution functions avoiding cancellation error.
dppois(y0,y1,mu,log.p=TRUE)Equivalent to log(ppois(y1,mu)-ppois(y0,mu)), but stable when y0 and y1 are highly improbable and in the same tail of the distribution (avoids cancellation to log(0)).
require(mgcv)
n <- 10
mu <- rep(2,n)
y0 <- c(0:5,10,23,0,2)
y1 <- c(1:6,11,1000,100,40)
dppois(y0,y1,mu)
#> [1] -1.3068528 -1.3068528 -1.7123179 -2.4054651 -3.3217558 -4.4203681
#> [7] -11.8776889 -40.0661024 -0.1454135 -1.1291016
log(ppois(y1,mu)-ppois(y0,mu))
#> [1] -1.3068528 -1.3068528 -1.7123179 -2.4054651 -3.3217558 -4.4203681
#> [7] -11.8776889 -Inf -0.1454135 -1.1291016