ZeroTruncatedNegativeBinomial: The Zero-Truncated Negative Binomial Distribution

ZeroTruncatedNegativeBinomialR Documentation

The Zero-Truncated Negative Binomial Distribution

Description

Density function, distribution function, quantile function and random generation for the Zero-Truncated Negative Binomial distribution with parameters size and prob.

Usage

dztnbinom(x, size, prob, log = FALSE)
pztnbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
qztnbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
rztnbinom(n, size, prob)

Arguments

x

vector of (strictly positive integer) quantiles.

q

vector of quantiles.

p

vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

size

target for number of successful trials, or dispersion parameter. Must be positive, need not be integer.

prob

parameter. 0 < prob <= 1.

log, log.p

logical; if TRUE, probabilities p are returned as \log(p).

lower.tail

logical; if TRUE (default), probabilities are P[X \le x], otherwise, P[X > x].

Details

The zero-truncated negative binomial distribution with size = r and prob = p has probability mass function

% p(x) = \frac{\Gamma(x + r) p^r (1 - p)^x}{\Gamma(r) x! (1 - p^r)}

for x = 1, 2, \ldots, r \ge 0 and 0 < p < 1, and p(1) = 1 when p = 1. The cumulative distribution function is

P(x) = \frac{F(x) - F(0)}{1 - F(0)},

where F(x) is the distribution function of the standard negative binomial.

The mean is r(1-p)/(p(1-p^r)) and the variance is [r(1-p)(1 - (1 + r(1-p))p^r)]/[p(1-p^r)]^2.

In the terminology of Klugman et al. (2012), the zero-truncated negative binomial is a member of the (a, b, 1) class of distributions with a = 1-p and b = (r-1)(1-p).

The limiting case size == 0 is the logarithmic distribution with parameter 1 - prob.

Unlike the standard negative binomial functions, parametrization through the mean mu is not supported to avoid ambiguity as to whether mu is the mean of the underlying negative binomial or the mean of the zero-truncated distribution.

If an element of x is not integer, the result of dztnbinom is zero, with a warning.

The quantile is defined as the smallest value x such that P(x) \ge p, where P is the distribution function.

Value

dztnbinom gives the (log) probability mass function, pztnbinom gives the (log) distribution function, qztnbinom gives the quantile function, and rztnbinom generates random deviates.

Invalid size or prob will result in return value NaN, with a warning.

The length of the result is determined by n for rztnbinom, and is the maximum of the lengths of the numerical arguments for the other functions.

Note

Functions {d,p,q}ztnbinom use {d,p,q}nbinom for all but the trivial input values and p(0).

rztnbinom uses the simple inversion algorithm suggested by Peter Dalgaard on the r-help mailing list on 1 May 2005 (https://stat.ethz.ch/pipermail/r-help/2005-May/070680.html).

Author(s)

Vincent Goulet vincent.goulet@act.ulaval.ca

References

Klugman, S. A., Panjer, H. H. and Willmot, G. E. (2012), Loss Models, From Data to Decisions, Fourth Edition, Wiley.

See Also

dnbinom for the negative binomial distribution.

dztgeom for the zero-truncated geometric and dlogarithmic for the logarithmic, which are special cases of the zero-truncated negative binomial.

Examples

## Example 6.3 of Klugman et al. (2012)
p <- 1/(1 + 0.5)
dztnbinom(c(1, 2, 3), size = 2.5, prob = p)
dnbinom(c(1, 2, 3), 2.5, p)/pnbinom(0, 2.5, p, lower = FALSE) # same

pztnbinom(1, 2, prob = 1)        # point mass at 1
dztnbinom(2, size = 1, 0.25)     # == dztgeom(2, 0.25)
dztnbinom(2, size = 0, 0.25)     # == dlogarithmic(2, 0.75)

qztnbinom(pztnbinom(1:10, 2.5, 0.3), 2.5, 0.3)

x <- rztnbinom(1000, size = 2.5, prob = 0.4)
y <- sort(unique(x))
plot(y, table(x)/length(x), type = "h", lwd = 2,
     pch = 19, col = "black", xlab = "x", ylab = "p(x)",
     main = "Empirical vs theoretical probabilities")
points(y, dztnbinom(y, size = 2.5, prob = 0.4),
       pch = 19, col = "red")
legend("topright", c("empirical", "theoretical"),
       lty = c(1, NA), lwd = 2, pch = c(NA, 19), col = c("black", "red"))

actuar documentation built on Nov. 8, 2023, 9:06 a.m.