Rpois generates NA by large means (lambda) in R

I am debugging a large set of nested models that encounter problems during optimization. During the process of zeroing by what, in my opinion, causes errors, I discovered unusual behavior in the function rpois().

It appears that with very large averages rpois(), returns instead NA. This problem does not raise a warning. See below for reproducible code set.

> rpois(1,3000000000)
[1] NA

My question is twofold:
1 - why does it show this behavior (is there a maximum size for an integer for the rpois function?) And
2 - is there work to prevent NA generation (even if it limits the size of the average input to a certain smaller value)?

I am running 32x R version 3.0.2 on 64x Windows 7.

+4
source share
1 answer

The problem is that it rpoisreturns an integer and converts the value to NAif the value is greater than the maximum possible integer value ( .Machine$integer.max).

rpois(1,.Machine$integer.max/1.00001)
## [1] 2147428954
rpois(1,.Machine$integer.max/1)
## [1] NA

The normal approximation should be insanely accurate in this case (usually this is very good if the average value is greater than 100!): If your average value is greater than (say) 0.999*.Machine$integer.max, you can useround(rnorm(1,mean=lambda,sd=sqrt(lambda)))

+6
source

Source: https://habr.com/ru/post/1541350/


All Articles