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.
The table below shows the functions for Poisson distributions 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\) |
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")
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")}
To set the parameter for the Poisson distribution function, with \(\tt{mean}=8\).
For example, for qpois()
, the following are the
same:
[1] 6
[1] 6
Sample 400 observations from the Poisson distribution with \(\tt{mean}=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")
Calculate the mass at \(x = 8\), in the Poisson distribution with \(\tt{mean}=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)
Calculate the cumulative distribution at \(x = 5\), in the Poisson distribution with \(\tt{mean}=6\). That is, \(P(X \le 5)\):
[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)
For upper tail, at \(x = 5\), that is, \(P(X > 5) = 1 - P(X \le 5)\), set the "lower.tail" argument:
[1] 0.5543204
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\):
[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)
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)\).
[1] 10
The feedback form is a Google form but it does not collect any personal information.
Please click on the link below to go to the Google form.
Thank You!
Go to Feedback Form
Copyright © 2020 - 2024. All Rights Reserved by Stats Codes