Here, we discuss Poisson distribution functions in R, plots, parameter setting, random sampling, mass function, cumulative distribution and quantiles.

The Poisson distribution with parameter \(\tt{mean\; or \; rate}=\lambda\) has probability mass function (pmf) formula as:

\[P(X=x)=\frac{\lambda^x e^{-\lambda}}{x!},\] for \(x \in \{0, 1, 2, \ldots\}\) number of occurrences,

where \(e\) is \(\tt{Euler's\;number}\) with \(e \approx 2.71828\),

and \(a!\), the \(\tt{factorial\; operator}\), equals \(a\times(a-1)\times(a-2)\times\cdots\times 1\).

The mean is \(\lambda\), and the variance is \(\lambda\).

See also probability distributions and plots and charts.

1 Table of Poisson Distribution Functions in R

The table below shows the functions for Poisson distributions in R.

Table of Poisson Distribution Functions in R
Function Usage
rpois(n, lambda) Simulate a random sample with \(n\) observations
dpois(x, lambda) Calculate the probability mass at the point \(x\)
ppois(q, lambda) Calculate the cumulative distribution at the point \(q\)
qpois(p, lambda) Calculate the quantile value associated with \(p\)

2 Plot of Poisson Distributions in R

Single distribution:

Below is a plot of the Poisson distribution function with \(\tt{mean}=14\).

x = 0:35; y = dpois(x, 14)
plot(x, y, type = "h",
     xlim = c(0, 35), ylim = c(0, max(y)),
     main = "Probability Mass Function of
Poisson Distribution (14)",
     xlab = "x", ylab = "Mass",
     col = "blue")
# Add legend
legend("topright", "mean = 14",
       fill = "blue",
       bty = "n")
Probability Mass Function (PMF) of a Poisson Distribution in R

Probability Mass Function (PMF) of a Poisson Distribution in R

Multiple distributions:

Below is a plot of multiple Poisson distribution functions in one graph.

x1 = 0:35; y1 = dpois(x1, 15)
x2 = 0:25; y2 = dpois(x2, 10)
x3 = 0:12; y3 = dpois(x3, 5)
plot(x1, y1,
     xlim = c(0, 35), ylim = range(c(y1, y2, y3)),
     main = "Probability Mass Functions of Poisson Distributions",
     xlab = "x", ylab = "Mass",
     col = "blue")
points(x2, y2, col = "red")
points(x3, y3, col = "green")
# Add legend
legend("topright", c("mean = 15",
                    "mean = 10",
                    "mean = 5"),
       fill = c("blue", "red", "green"),
       bty = "n")
# Add lines
for(i in 1:35){
  segments(x1[i], dpois(x1[i], 15),
           x1[i+1], dpois(x1[i+1], 15),
           col = "blue")}
for(i in 1:25){
  segments(x2[i], dpois(x2[i], 10),
           x2[i+1], dpois(x2[i+1], 10),
           col = "red")}
for(i in 1:12){
  segments(x3[i], dpois(x3[i], 5),
           x3[i+1], dpois(x3[i+1], 5),
           col = "green")}
Probability Mass Functions (PMFs) of Poisson Distributions in R

Probability Mass Functions (PMFs) of Poisson Distributions in R

3 Examples for Setting Parameters for Poisson Distributions in R

To set the parameter for the Poisson distribution function, with \(\tt{mean}=8\).

For example, for qpois(), the following are the same:

qpois(0.3, 8)
[1] 6
qpois(0.3, lambda = 8)
[1] 6

4 rpois(): Random Sampling from Poisson Distributions in R

Sample 400 observations from the Poisson distribution with \(\tt{mean}=20\):

rpois(400, 20)
set.seed(123) # Line allows replication (use any number).
sample = rpois(400, 20)
hist(sample,
     main = "Histogram of 400 Observations from
Poisson Distribution with Mean = 20",
     xlab = "x",
     col = "lightblue", border = "white")
Histogram of Poisson Distribution (20) Random Sample in R

Histogram of Poisson Distribution (20) Random Sample in R

5 dpois(): Probability Mass Function for Poisson Distributions in R

Calculate the mass at \(x = 8\), in the Poisson distribution with \(\tt{mean}=12\):

dpois(8, 12)
[1] 0.06552328
x = 0:25; y = dpois(x, 12)
plot(x, y,
     xlim = c(0, 25), ylim = c(0, max(y)),
     main = "Probability Mass Function of Poisson Distribution
with Mean = 12",
     xlab = "x", ylab = "Mass",
     col = "blue")
# Add lines
segments(8, -1, 8, 0.06552328)
segments(-1, 0.06552328, 8, 0.06552328)
Probability Mass Function (PMF) of Poisson Distribution (12) in R

Probability Mass Function (PMF) of Poisson Distribution (12) in R

6 ppois(): Cumulative Distribution Function for Poisson Distributions in R

Calculate the cumulative distribution at \(x = 5\), in the Poisson distribution with \(\tt{mean}=6\). That is, \(P(X \le 5)\):

ppois(5, 6)
[1] 0.4456796
x = 0:15; y = ppois(x, 6)
plot(x, y,
     xlim = c(0, 15), ylim = c(0, 1),
     main = "Cumulative Distribution Function of Poisson Distribution
with Mean = 6",
     xlab = "x", ylab = "Cumulative Distribution",
     col = "blue")
# Add lines
for(i in 1:15){
  segments(x[i], ppois(x[i], 6),
           x[i] + 1, ppois(x[i], 6),
           col = "blue")
}
segments(5, -1, 5, 0.4456796)
segments(-1, 0.4456796, 5, 0.4456796)
Cumulative Distribution Function (CDF) of Poisson Distribution (6) in R

Cumulative Distribution Function (CDF) of Poisson Distribution (6) in R

For upper tail, at \(x = 5\), that is, \(P(X > 5) = 1 - P(X \le 5)\), set the "lower.tail" argument:

ppois(5, 6, lower.tail = FALSE)
[1] 0.5543204

7 qpois(): Derive Quantile for Poisson Distributions in R

Derive the quantile for \(p = 0.85\), in the Poisson distribution with \(\tt{mean}=7\). That is, the \(\tt{smallest}\) \(x\) such that, \(P(X\le x) \ge 0.85\):

qpois(0.85, 7)
[1] 10
x = 0:16; y = ppois(x, 7)
plot(x, y,
     xlim = c(0, 16), ylim = c(0, 1),
     main = "Cumulative Distribution Function of Poisson Distribution
with Mean = 7",
     xlab = "x", ylab = "Cumulative Distribution",
     col = "blue")
# Add lines
for(i in 1:16){
  segments(x[i], ppois(x[i], 7),
           x[i] + 1, ppois(x[i], 7),
           col = "blue")
}
segments(10, -1, 10, 0.85)
segments(-1, 0.85, 10, 0.85)
Cumulative Distribution Function (CDF) of Poisson Distribution (7) in R

Cumulative Distribution Function (CDF) of Poisson Distribution (7) in R

For upper tail, for \(p = 0.15\), that is, the \(\tt{smallest}\) \(x\) such that, \(P(X > x) < 0.15\):

Note: \(P(X > x) = 1-P(X \le x)\).

qpois(0.15, 7, lower.tail = FALSE)
[1] 10

Copyright © 2020 - 2024. All Rights Reserved by Stats Codes