GammaPoiss function

Gamma-Poisson distribution

Gamma-Poisson distribution

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

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[Xx]P[X \le x]

    otherwise, P[X>x]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(λ)X ~ Poisson(\lambda)

and λ Gamma(α,β)\lambda ~ Gamma(\alpha, \beta), then X GammaPoisson(α,β)X ~ Gamma-Poisson(\alpha, \beta).

Probability mass function

f(x)=Γ(α+x)x!Γ(α)(β1+β)x(1β1+β)\alphaf(x)=Γ(α+x)/(x!Γ(α))(β/(1+β))x(1β/(1+β))α f(x) = \frac{\Gamma(\alpha+x)}{x! \, \Gamma(\alpha)} \left(\frac{\beta}{1+\beta}\right)^x \left(1-\frac{\beta}{1+\beta}\right)^\alphaf(x) = \Gamma(\alpha+x) / (x!*\Gamma(\alpha)) * (\beta/(1+\beta))^x * (1-\beta/(1+\beta))^\alpha

Cumulative distribution function is calculated using recursive algorithm that employs the fact that Γ(x)=(x1)!\Gamma(x) = (x - 1)!. This enables re-writing probability mass function as

f(x)=(α+x1)!x!Γ(α)(β1+β)x(1β1+β)\alphaf(x)=((α+x1)!)/(x!Γ(α))(β/(1+β))x(1β/(1+β))α f(x) = \frac{(\alpha+x-1)!}{x! \, \Gamma(\alpha)} \left( \frac{\beta}{1+\beta} \right)^x \left( 1- \frac{\beta}{1+\beta} \right)^\alphaf(x) = ((\alpha+x-1)!)/(x!*\Gamma(\alpha))*(\beta/(1+\beta))^x*(1-\beta/(1+\beta))^\alpha

what makes recursive updating from xx to x+1x+1 easy using the properties of factorials

f(x+1)=(α+x1)!(α+x)x!(x+1)Γ(α)(β1+β)x(β1+β)(1β1+β)\alphaf(x+1)=((α+x1)!(α+x))/(x!(x+1)Γ(α))(β/(1+β))x(β/(1+β))(1β/(1+β))α f(x+1) = \frac{(\alpha+x-1)! \, (\alpha+x)}{x! \,(x+1) \, \Gamma(\alpha)} \left( \frac{\beta}{1+\beta} \right)^x \left( \frac{\beta}{1+\beta} \right) \left( 1- \frac{\beta}{1+\beta} \right)^\alphaf(x+1) = ((\alpha+x-1)!*(\alpha+x))/(x!*(x+1)*\Gamma(\alpha))*(\beta/(1+\beta))^x*(\beta/(1+\beta))*(1-\beta/(1+\beta))^\alpha

and let's us efficiently calculate cumulative distribution function as a sum of probability mass functions

F(x)=k=0xf(k)F(x)=f(0)+...+f(x) F(x) = \sum_{k=0}^x f(k)F(x) = f(0)+...+f(x)

Examples

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)) xx <- seq(0, 12000, by = 0.1) plot(ecdf(x)) lines(xx, pgpois(xx, 7, 0.002), col = "red", lwd = 2)

See Also

Gamma, Poisson

  • Maintainer: Tymoteusz Wolodzko
  • License: GPL-2
  • Last published: 2023-11-30