urnbinom function

UNU.RAN Negative Binomial random variate generator

UNU.RAN Negative Binomial random variate generator

UNU.RAN random variate generator for the Negative Binomial distribution with with parameters size and prob. It also allows sampling from the truncated distribution.

[Special Generator] -- Sampling Function: Negative Binomial.

urnbinom(n, size, prob, lb = 0, ub = Inf)

Arguments

  • n: size of required sample.
  • size: target for number of successful trials, or dispersion parameter (the shape parameter of the gamma mixing distribution). Must be strictly positive.
  • prob: probability of success in each trial. 0 < prob <= 1.
  • lb: lower bound of (truncated) distribution.
  • ub: upper bound of (truncated) distribution.

Details

The Negative Binomial distribution with size =n= n and prob =p= p has density

p(x)=Γ(x+n)Γ(n)x!pn(1p)xp(x)=Gamma(x+n)/(Gamma(n)x!)pn(1p)x p(x) = \frac{\Gamma(x+n)}{\Gamma(n) x!} p^n (1-p)^xp(x) = Gamma(x+n)/(Gamma(n) x!) p^n (1-p)^x

for x=0,1,2,x = 0, 1, 2, \ldots, n>0n > 0 and 0<p10 < p \le 1. This represents the number of failures which occur in a sequence of Bernoulli trials before a target number of successes is reached.

The generation algorithm uses guide table based inversion when the tails are not too heavy and method DARI otherwise. The parameters lb and ub can be used to generate variates from the Negative Binomial distribution truncated to the interval (lb,ub).

See Also

runif and .Random.seed about random number generation, unuran for the UNU.RAN class, and rnbinom for the built-in generator.

References

W. H"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg

Author(s)

Josef Leydold and Wolfgang H"ormann unuran@statmath.wu.ac.at .

Note

This function is wrapper for the UNU.RAN class in . Compared to rnbinom, urnbinom is faster, especially for larger sample sizes. However, in opposition to rnbinom vector arguments are ignored, i.e. only the first entry is used.

Examples

## Create a sample of size 1000 x <- urnbinom(n=1000,size=10,prob=0.3)
  • Maintainer: Josef Leydold
  • License: GPL (>= 2)
  • Last published: 2025-04-07