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

dist_negative_binomial

The Negative Binomial distribution


Description

[Stable]

Usage

dist_negative_binomial(size, prob)

Arguments

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.

Details

A generalization of the geometric distribution. It is the number of failures in a sequence of i.i.d. Bernoulli trials before a specified number of successes (size) occur. The probability of success in each trial is given by prob.

We recommend reading this documentation on https://pkg.mitchelloharawild.com/distributional/, where the math will render nicely.

In the following, let X be a Negative Binomial random variable with success probability prob = p and the number of successes size = r.

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)!/(k!(r-1)!) (1-p)^r p^k

Cumulative distribution function (c.d.f):

Too nasty, omitted.

Moment generating function (m.g.f):

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

See Also

Examples

dist <- dist_negative_binomial(size = 10, prob = 0.5)

dist
mean(dist)
variance(dist)
skewness(dist)
kurtosis(dist)

generate(dist, 10)

density(dist, 2)
density(dist, 2, log = TRUE)

cdf(dist, 4)

quantile(dist, 0.7)

distributional

Vectorised Probability Distributions

v0.2.2
GPL-3
Authors
Mitchell O'Hara-Wild [aut, cre] (<https://orcid.org/0000-0001-6729-7695>), Earo Wang [ctb] (<https://orcid.org/0000-0001-6448-5260>), Matthew Kay [ctb] (<https://orcid.org/0000-0001-9446-0419>), Alex Hayes [aut] (<https://orcid.org/0000-0002-4985-5160>)
Initial release

We don't support your browser anymore

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