Learn R Programming

extraDistr (version 1.8.1)

GammaPoiss: Gamma-Poisson distribution

Description

Probability mass function and random generation for the gamma-Poisson distribution.

Usage

dgpois(x, shape, rate, scale = 1/rate, log = FALSE)
pgpois(q, shape, rate, scale = 1/rate, lower.tail = TRUE, log.p = FALSE)
rgpois(n, shape, rate, scale = 1/rate)

Arguments

x, q
vector of quantiles.
shape, scale
shape and scale parameters. Must be positive, scale strictly.
rate
an alternative way to specify the scale.
log, log.p
logical; if TRUE, probabilities p are given as log(p).
lower.tail
logical; if TRUE (default), probabilities are $P[X \le x]$ otherwise, $P[X > x]$.
n
number of observations. If length(n) > 1, the length is taken to be the number required.

Details

Gamma-Poisson distribution arises as a continuous mixture of Poisson distributions, where the mixing distribution of the Poisson rate $\lambda$ is a gamma distribution. When $X ~ Poisson(\lambda)$ and $\lambda ~ Gamma(\alpha, \beta)$, then $X ~ Gamma-Poisson(\alpha, \beta)$.

Probability density function (parametrized by scale) $$ f(x) = \frac{\Gamma(\alpha+x)}{x! \Gamma(\alpha)} \left(\frac{\beta}{1+\beta}\right)^k \left(1-\frac{\beta}{1+\beta}\right)^\alpha $$

Warning: cumulative distribution function is defined as $$F(x) = \sum_{k=0}^x f(k)$$ so it may be slow for large datasets.

See Also

Gamma, Poisson

Examples

Run this code

x <- rgpois(1e5, 7, 0.002)
xx <- seq(0, 12000, by = 1)
hist(x, 100, freq = FALSE)
lines(xx, dgpois(xx, 7, 0.002), col = "red")
hist(pgpois(x, 7, 0.002))
plot(ecdf(x))
lines(xx, pgpois(xx, 7, 0.002), col = "red", lwd = 2)

Run the code above in your browser using DataLab