[Rd] Random Count Generation with rnbinom

Dario Strbenac dstr7320 at uni.sydney.edu.au
Sun Feb 23 03:00:23 CET 2014


The documentation states :

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

However, this fails :

> rnbinom(10, mu = 100, size = 0)
 [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 :

> rnbinom(10, mu = 100, size = 0.000001)
 [1] 0 0 0 0 0 0 0 0 0 0

It also fails for underdispersed count models :

> rnbinom(10, mu = 100, size = -0.1)
 [1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Warning message:
In rnbinom(10, mu = 100, size = -0.1) : NAs produced

> sessionInfo()
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


More information about the R-devel mailing list