# Poisson: The Poisson Distribution

## Description

Density, distribution function, quantile function and random generation for the Poisson distribution with parameter `lambda`.

## Usage

 ```1 2 3 4``` ```dpois(x, lambda, log = FALSE) ppois(q, lambda, lower.tail = TRUE, log.p = FALSE) qpois(p, lambda, lower.tail = TRUE, log.p = FALSE) rpois(n, lambda) ```

## Arguments

 `x` vector of (non-negative integer) quantiles. `q` vector of quantiles. `p` vector of probabilities. `n` number of random values to return. `lambda` vector of (non-negative) means. `log, log.p` logical; if TRUE, probabilities p are given as log(p). `lower.tail` logical; if TRUE (default), probabilities are P[X ≤ x], otherwise, P[X > x].

## Details

The Poisson distribution has density

p(x) = λ^x exp(-λ)/x!

for x = 0, 1, 2, … . The mean and variance are E(X) = Var(X) = λ.

Note that λ = 0 is really a limit case (setting 0^0 = 1) resulting in a point mass at 0, see also the example.

If an element of `x` is not integer, the result of `dpois` is zero, with a warning. p(x) is computed using Loader's algorithm, see the reference in `dbinom`.

The quantile is right continuous: `qpois(p, lambda)` is the smallest integer x such that P(X ≤ x) ≥ p.

Setting `lower.tail = FALSE` allows to get much more precise results when the default, `lower.tail = TRUE` would return 1, see the example below.

## Value

`dpois` gives the (log) density, `ppois` gives the (log) distribution function, `qpois` gives the quantile function, and `rpois` generates random deviates.

Invalid `lambda` will result in return value `NaN`, with a warning.

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

The numerical arguments other than `n` are recycled to the length of the result. Only the first elements of the logical arguments are used.

`rpois` returns a vector of type integer unless generated values exceed the maximum representable integer when `double` values are returned since R version 4.0.0.

## Source

`dpois` uses C code contributed by Catherine Loader (see `dbinom`).

`ppois` uses `pgamma`.

`qpois` uses the Cornish–Fisher Expansion to include a skewness correction to a normal approximation, followed by a search.

`rpois` uses

Ahrens, J. H. and Dieter, U. (1982). Computer generation of Poisson deviates from modified normal distributions. ACM Transactions on Mathematical Software, 8, 163–179.

Distributions for other standard distributions, including `dbinom` for the binomial and `dnbinom` for the negative binomial distribution.

`poisson.test`.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18``` ```require(graphics) -log(dpois(0:7, lambda = 1) * gamma(1+ 0:7)) # == 1 Ni <- rpois(50, lambda = 4); table(factor(Ni, 0:max(Ni))) 1 - ppois(10*(15:25), lambda = 100) # becomes 0 (cancellation) ppois(10*(15:25), lambda = 100, lower.tail = FALSE) # no cancellation par(mfrow = c(2, 1)) x <- seq(-0.01, 5, 0.01) plot(x, ppois(x, 1), type = "s", ylab = "F(x)", main = "Poisson(1) CDF") plot(x, pbinom(x, 100, 0.01), type = "s", ylab = "F(x)", main = "Binomial(100, 0.01) CDF") ## The (limit) case lambda = 0 : stopifnot(identical(dpois(0,0), 1), identical(ppois(0,0), 1), identical(qpois(1,0), 0)) ```

### Example output ``` 1 1 1 1 1 1 1 1

0  1  2  3  4  5  6  7  8  9
0  1  5 13 14  9  3  2  2  1
 1.233094e-06 1.261664e-08 7.085799e-11 2.252643e-13 4.440892e-16
 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
 0.000000e+00
 1.233094e-06 1.261664e-08 7.085800e-11 2.253110e-13 4.174239e-16
 4.626179e-19 3.142097e-22 1.337219e-25 3.639328e-29 6.453883e-33
 7.587807e-37
```