[Rd] dnbinom with a large size parameter (PR#13650)

4ap1 at queensu.ca 4ap1 at queensu.ca
Mon Apr 13 03:40:12 CEST 2009

Full_Name: Andrey Pavlov
Version: 2.7.1 (2008-06-23)
OS: Windows Vista
Submission from: (NULL) (

Dear developers,

I discovered an issue with the dnbinom function while fitting a negative
binomial model to my data. I was using the size and mu parameterization. When
the size gets large enough, the function begins to return 1, while it should
instead return the respective Poisson probability. This can be seen in the
following simple example:

> dpois(1,lambda=1)
[1] 0.3678794
> dnbinom(1,size=1e+15,mu=1)
[1] 0.3678793
> dnbinom(1,size=3e+15,mu=1)
[1] 0.3678793

- very close to Poisson. But then I increase the size further, and it goes off

> dnbinom(1,size=5e+15,mu=1)
[1] 0.3658024
> dnbinom(1,size=7e+15,mu=1)
[1] 0.3572676

...until suddenly it returns 1:
> dnbinom(1,size=10e+15,mu=1)
[1] 1

This turned out to be a big and hard to track down issue for me. The bug
confused the optimizer of the likelihood function, which happened to move too
far on the size dimension and began to discover "very good" parameters. I fixed
the problem by adding a logical check, which replaced the negative binomial
probability with the Poisson one in case the size was large, but this is a very
crude solution. Perhaps it is worth fixing the internal routine.


More information about the R-devel mailing list