Learn R Programming

distr6 (version 1.3.2)

NegativeBinomial: Negative Binomial Distribution Class

Description

Mathematical and statistical functions for the Negative Binomial distribution, which is commonly used to model the number of successes, trials or failures before a given number of failures or successes.

Value

Returns an R6 object inheriting from class SDistribution.

Constructor

NegativeBinomial$new(size = 10, prob = 0.5, qprob = NULL, mean = NULL, form = "fbs", decorators = NULL, verbose = FALSE)

Constructor Arguments

Argument Type Details
size numeric number of failures/successes.
prob numeric probability of success.
qprob numeric probability of failure.
mean numeric location parameter.
form character form of negative binomial, see details.

decorators Decorator decorators to add functionality. See details.

Constructor Details

The Negative Binomial distribution is parameterised with size as a positive whole number, and either prob or qprob as a number between 0 and 1, or mean as a numeric greater than the number of failures/successes (if form is 'tbf' or 'tbs'). These are related via, $$qprob = 1 - prob$$ and the mean formula is dependent on the form. If mean is given then qprob and prob are ignored. If qprob is given then prob is ignored. The additional form argument determines which of the four Negative Binomial distributions should be constructed, this cannot be updated after construction. form should be one of "sbf" (successes before failures), "tbf" (trials before failures), "fbs" (failures before successes) or "tbs" (trials before successes). "fbs" is taken as default if none are supplied or an unrecognised form is given.

Public Variables

Variable Return
name Name of distribution.
short_name Id of distribution.
description Brief description of distribution.

Public Methods

Accessor Methods Link
decorators() decorators
traits() traits
valueSupport() valueSupport
variateForm() variateForm
type() type
properties() properties
support() support
symmetry() symmetry
sup() sup
inf() inf
dmax() dmax
dmin() dmin
skewnessType() skewnessType
kurtosisType() kurtosisType

Statistical Methods

Link
pdf(x1, ..., log = FALSE, simplify = TRUE) pdf
cdf(x1, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) cdf
quantile(p, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) quantile.Distribution
rand(n, simplify = TRUE) rand
mean() mean.Distribution
variance() variance
stdev() stdev
prec() prec
cor() cor
skewness() skewness
kurtosis(excess = TRUE) kurtosis
entropy(base = 2) entropy
mgf(t) mgf
cf(t) cf
pgf(z) pgf
median() median.Distribution
iqr() iqr
mode(which = "all") mode

Parameter Methods

Link
parameters(id) parameters
getParameterValue(id, error = "warn") getParameterValue
setParameterValue(..., lst = NULL, error = "warn") setParameterValue

Validation Methods

Link
liesInSupport(x, all = TRUE, bound = FALSE) liesInSupport
liesInType(x, all = TRUE, bound = FALSE) liesInType

Representation Methods

Link
strprint(n = 2) strprint
print(n = 2) print
summary(full = T) summary.Distribution

Details

The Negative Binomial distribution parameterised with number of failures before successes, \(n\), and probability of success, \(p\), is defined by the pmf, $$f(x) = C(x + n - 1, n - 1) p^n (1 - p)^x$$ for \(n = {0,1,2,\ldots}\) and \(p \epsilon [0,1]\), where \(C(a,b)\) is the combination (or binomial coefficient) function.

The distribution is supported on \({0,1,2,\ldots}\) (for fbs and sbf) or \({n,n+1,n+2,\ldots}\) (for tbf and tbs) (see below).

The Negative Binomial distribution can refer to one of four distributions (forms): 1. The number of failures before K successes (fbs) 2. The number of successes before K failures (sbf) 3. The number of trials before K failures (tbf) 4. The number of trials before K successes (tbs) For each we refer to the number of K successes/failures as the size parameter, prob is always the probability of success and qprob is the probability of failure. Use $description to see the Negative Binomial form.

References

McLaughlin, M. P. (2001). A compendium of common probability distributions (pp. 2014-01). Michael P. McLaughlin.

See Also

listDistributions for all available distributions. Binomial for the Binomial distribution and Geometric for the Geometric distribution.

Examples

Run this code
# NOT RUN {
# Different parameterisations
NegativeBinomial$new(size = 5, prob = 0.2)
NegativeBinomial$new(size = 5, qprob = 0.2)
NegativeBinomial$new(size = 5, mean = 4)

# Different forms of the distribution
NegativeBinomial$new(form = "fbs")
NegativeBinomial$new(form = "sbf")

# Use description to see which form is used
NegativeBinomial$new(form = "tbf")
NegativeBinomial$new(form = "tbs")

x <- NegativeBinomial$new() # Default is size = 10, prob = 0.5 and failures before successes

# Update parameters (form cannot be updated)
x$setParameterValue(qprob = 0.2)  # When any parameter is updated, all others are too!
x$parameters()


# d/p/q/r
x$pdf(5)
x$cdf(5)
x$quantile(0.42)
x$rand(4)

# Statistics
x$mean()
x$variance()

summary(x)
# }

Run the code above in your browser using DataLab