Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rnegbin

Simulate Negative Binomial Variates


Description

Function to generate random outcomes from a Negative Binomial distribution, with mean mu and variance mu + mu^2/theta.

Usage

rnegbin(n, mu = n, theta = stop("'theta' must be specified"))

Arguments

n

If a scalar, the number of sample values required. If a vector, length(n) is the number required and n is used as the mean vector if mu is not specified.

mu

The vector of means. Short vectors are recycled.

theta

Vector of values of the theta parameter. Short vectors are recycled.

Details

The function uses the representation of the Negative Binomial distribution as a continuous mixture of Poisson distributions with Gamma distributed means. Unlike rnbinom the index can be arbitrary.

Value

Vector of random Negative Binomial variate values.

Side Effects

Changes .Random.seed in the usual way.

Examples

# Negative Binomials with means fitted(fm) and theta = 4.5
fm <- glm.nb(Days ~ ., data = quine)
dummy <- rnegbin(fitted(fm), theta = 4.5)

MASS

Support Functions and Datasets for Venables and Ripley's MASS

v7.3-54
GPL-2 | GPL-3
Authors
Brian Ripley [aut, cre, cph], Bill Venables [ctb], Douglas M. Bates [ctb], Kurt Hornik [trl] (partial port ca 1998), Albrecht Gebhardt [trl] (partial port ca 1998), David Firth [ctb]
Initial release
2021-04-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.