NegBinomial
The Negative Binomial Distribution

Description

Calculates density, cumulative probability, quantile, and generate random sample for the negative binomial distribution (discrete).

Usage

dnbinom(x, size, prob, mu, log = FALSE) # density
pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE) # probability
qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE) # quantile
rnbinom(n, size, prob, mu) # random

Arguments

x, q numeric vectors in the range [0, Inf) that specify the quantiles.
p a numeric vector in the range [0, 1] that specifies the probabilities.
n an integer value in the range [0, Inf) that specifies the number of random samples requested. If the input value is not an integer, it is truncated. If length(n) is greater than 1, the random function returns length(n) random samples.
size a numeric vector in the range [0, Inf) that specifies the number of successes.
prob a numeric vector in the range [0, 1] that specifies the probability of a success.
mu a numeric vector in the range [0, Inf) that provides an alternative parameterization for prob. If mu is provided but prob is not, then prob=size/(mu+size). mu is ignored if prob is supplied.
log a logical value. If FALSE (default), the density function returns the density itself. If TRUE, it returns the log of the density.
lower.tail a logical value. If TRUE (default), the probability supplied to the quantile function or returned by the probability function is P[X <= x]. If FALSE, it is P[X > x].
log.p a logical value. If FALSE (default), the probability supplied to the quantile function or returned by the probability function is the probability itself. If TRUE, it is the log of the probability.

Details

The distribution parameter(s) are replicated cyclically to be the same length as the input x, q, p, or the number of random samples requested.
Missing values (NAs) in the input or the distribution parameter(s) will cause the corresponding elements of the result to be missing.
Value
returns density (dnbinom), cumulative probability (pnbinom), quantile (qnbinom), or random sample (rnbinom) for the negative binomial distribution with parameters size and prob (or alternatively mu). The quantile is defined as the smallest value q such that Pr(negative binomial random variate <= q) >= p.
Side Effects
If the .Random.seed dataset exists, the random sample function updates its value. The random sample function creates the .Random.seed dataset if it does not exist.
Background
The negative binomial distribution is the discrete probability distribution of the number of failures in a sequence of independent experiments, each of which has two possible outcomes (yes/no) (i.e., a Bernoulli trial) and yields success with probability prob, before size successes occur. It has support on the integer set {0, 1, 2, 3, …}.
See Also
set.seed, Binomial
Examples
dnbinom(3, 10, .6)  # same as: choose(10+3-1, 3) * 0.6^10 * 0.4^3
# 20 random values from Negative Binomial with mean 10*(1-.8)/0.8 = 2.5:
rnbinom(20, 10, 0.8)
Package stats version 6.1.1-7
Package Index