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

NegativeBinomial

Create a Negative Binomial distribution


Description

A generalization of the geometric distribution. It is the number of successes in a sequence of i.i.d. Bernoulli trials before a specified number (r) of failures occurs.

Usage

NegativeBinomial(size, p = 0.5)

Arguments

size

The number of failures (an integer greater than 0) until the experiment is stopped. Denoted r below.

p

The success probability for a given trial. p can be any value in [0, 1], and defaults to 0.5.

Details

We recommend reading this documentation on https://alexpghayes.github.io/distributions3, where the math will render with additional detail and much greater clarity.

In the following, let X be a Negative Binomial random variable with success probability p = p.

Support: \{0, 1, 2, 3, ...\}

Mean: \frac{p r}{1-p}

Variance: \frac{pr}{(1-p)^2}

Probability mass function (p.m.f):

f(k) = {k + r - 1 \choose k} \cdot (1-p)^r p^k

Cumulative distribution function (c.d.f):

Too nasty, ommited.

Moment generating function (m.g.f):

\frac{(1-p)^r}{(1-pe^t)^r}, t < -\log p

Value

A NegativeBinomial object.

See Also

Examples

set.seed(27)

X <- NegativeBinomial(10, 0.3)
X

random(X, 10)

pdf(X, 2)
log_pdf(X, 2)

cdf(X, 4)
quantile(X, 0.7)

distributions3

Probability Distributions as S3 Objects

v0.1.1
MIT + file LICENSE
Authors
Alex Hayes [aut, cre] (<https://orcid.org/0000-0002-4985-5160>), Ralph Moller-Trane [aut], Emil Hvitfeldt [ctb] (<https://orcid.org/0000-0002-0679-1945>), Daniel Jordan [ctb], Bruna Wundervald [ctb]
Initial release

We don't support your browser anymore

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