ZeroTruncatedBinomial {actuar}R Documentation

The Zero-Truncated Binomial Distribution

Description

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

Usage

dztbinom(x, size, prob, log = FALSE)
pztbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
qztbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE)
rztbinom(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

number of trials (strictly positive integer).

prob

probability of success on each trial. 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 ≤ x], otherwise, P[X > x].

Details

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

p(x) = choose(n, x) [p^x (1-p)^(n-x)]/[1 - (1-p)^n]

for x = 1, …, n and 0 < p ≤ 1, and p(1) = 1 when p = 0. The cumulative distribution function is

P(x) = [F(x) - F(0)]/[1 - F(0)],

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

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

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

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

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

Value

dztbinom gives the probability mass function, pztbinom gives the distribution function, qztbinom gives the quantile function, and rztbinom 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 rztbinom, and is the maximum of the lengths of the numerical arguments for the other functions.

Note

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

rztbinom 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

dbinom for the binomial distribution.

Examples

dztbinom(1:5, size = 5, prob = 0.4)
dbinom(1:5, 5, 0.4)/pbinom(0, 5, 0.4, lower = FALSE) # same

pztbinom(1, 2, prob = 0)        # point mass at 1

qztbinom(pztbinom(1:10, 10, 0.6), 10, 0.6)

n <- 8; p <- 0.3
x <- 0:n
title <- paste("ZT Binomial(", n, ", ", p,
               ") and Binomial(", n, ", ", p,") PDF",
               sep = "")
plot(x, dztbinom(x, n, p), type = "h", lwd = 2, ylab = "p(x)",
     main = title)
points(x, dbinom(x, n, p), pch = 19, col = "red")
legend("topright", c("ZT binomial probabilities", "Binomial probabilities"),
       col = c("black", "red"), lty = c(1, 0), lwd = 2, pch = c(NA, 19))

[Package actuar version 3.1-4 Index]