vnbinom {simEd}R Documentation

Variate Generation for Negative Binomial Distribution

Description

Variate Generation for Negative Binomial Distribution

Usage

vnbinom(n, size, prob, mu, stream = NULL, antithetic = FALSE, asList = FALSE)

Arguments

n

number of observations

size

target for number of successful trials, or dispersion parameter (the shape parameter of the gamma mixing distribution). Must be strictly positive, need not be integer.

prob

Probability of success in each trial; '0 < prob <= 1'

mu

alternative parameterization via mean

stream

if NULL (default), uses stats::runif to generate uniform variates to invert via stats::qnbinom; otherwise, an integer in 1:25 indicates the rstream stream from which to generate uniform variates to invert via stats::qnbinom;

antithetic

if FALSE (default), inverts u = uniform(0,1) variate(s) generated via either stats::runif or rstream::rstream.sample; otherwise, uses 1 - u

asList

if FALSE (default), output only the generated random variates; otherwise, return a list with components suitable for visualizing inversion. See return for details

Details

Generates random variates from the negative binomial distribution.

Negative Binomial variates are generated by inverting uniform(0,1) variates produced either by stats::runif (if stream is NULL) or by rstream::rstream.sample (if stream is not NULL). In either case, stats::qnbinom is used to invert the uniform(0,1) variate(s). In this way, using vnbinom provides a monotone and synchronized binomial variate generator, although not particularly fast.

The stream indicated must be an integer between 1 and 25 inclusive.

The negative binomial distribution with size = n and prob = p has density

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

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

The mean is \mu = n(1 - p)/p and variance n(1 - p)/p^2

Value

If asList is FALSE (default), return a vector of random variates.

Otherwise, return a list with components suitable for visualizing inversion, specifically:

u

A vector of generated U(0,1) variates

x

A vector of negative binomial random variates

quantile

Parameterized quantile function

text

Parameterized title of distribution

Author(s)

Barry Lawson (blawson@bates.edu),
Larry Leemis (leemis@math.wm.edu),
Vadim Kudlay (vkudlay@nvidia.com)

See Also

rstream, set.seed, stats::runif

stats::rnbinom

Examples

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qnbinom
 vnbinom(3, size = 10, mu = 10)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qnbinom
 vnbinom(3, 10, 0.25, stream = 1)
 vnbinom(3, 10, 0.25, stream = 2)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qnbinom
 vnbinom(1, 10, 0.25, stream = 1)
 vnbinom(1, 10, 0.25, stream = 2)
 vnbinom(1, 10, 0.25, stream = 1)
 vnbinom(1, 10, 0.25, stream = 2)
 vnbinom(1, 10, 0.25, stream = 1)
 vnbinom(1, 10, 0.25, stream = 2)

 set.seed(8675309)
 variates <- vnbinom(100, 10, 0.25, stream = 1)
 set.seed(8675309)
 variates <- vnbinom(100, 10, 0.25, stream = 1, antithetic = TRUE)


[Package simEd version 2.0.1 Index]