Skip to content
Prev 47658 / 63421 Next

Random Count Generation with rnbinom

The documentation states :

An alternative parametrization (often used in ecology) is by the mean ?mu?, and ?size?, the dispersion parameter.

However, this fails :
[1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Warning message:
In rnbinom(10, mu = 100, size = 0) : NAs produced

For dispersion set to 0, it should work like drawing from a Poisson distribution.

It also produces incorrect draws for non-zero dispersions :
[1] 0 0 0 0 0 0 0 0 0 0

It also fails for underdispersed count models :
[1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Warning message:
In rnbinom(10, mu = 100, size = -0.1) : NAs produced
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8    
 [5] LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.0.2

--------------------------------------
Dario Strbenac
PhD Student
University of Sydney
Camperdown NSW 2050
Australia