Poisson Functions in R Programming

Poisson distribution

Poisson distribution is a discrete probability distribution that describes the number of independent events that occur in a fixed interval of time or space. It is named after the French mathematician Siméon Denis Poisson, who introduced it in the early 19th century.

The Poisson distribution is characterized by a single parameter λ (lambda), which represents the average rate at which events occur. The probability mass function (PMF) of the Poisson distribution is given by:

P(X = k) = e^(-λ) * λ^k / k!

where k is a non-negative integer and k! is the factorial of k.

The mean and variance of the Poisson distribution are both equal to λ. This means that the distribution becomes more concentrated around the mean as λ increases.

The Poisson distribution is often used to model rare events such as accidents, defects, or occurrences of a specific disease in a population. It is also used in queueing theory, reliability analysis, and other fields where the occurrence of discrete events is of interest.

In summary, the Poisson distribution is a probability distribution that models the number of independent events occurring within a fixed interval of time or space, where the mean and variance of the distribution are equal to λ, the average rate of occurrence.

In R programming, there are several built-in functions that can be used to work with Poisson distributions. Here are some commonly used Poisson functions in R:

1. dpois() function in R

dpois() function is used to calculate the probability mass function (PMF) for a given Poisson distribution. It takes two arguments: the value at which to evaluate the PMF and the mean of the Poisson distribution.

For example, to calculate the PMF at x = 3 for a Poisson distribution with a mean of 2.5, you can use the following code:

 

dpois(3, 2.5)
# Plot PMF for Poisson distribution with 
# mean of 2.5 for x = 0 to 10
x <- seq(0, 10, by = 1)
pmf <- dpois(x, 2.5)
plot(
x,
pmf,
type = "h",
lwd = 3,
main = "Poisson PMF",
xlab = "Number of events",
ylab = "Probability"
)

 

This will create a plot of the PMF for the Poisson distribution with a mean of 2.5, showing the probability of observing each number of events from 0 to 10. The type = "h" argument specifies that a histogram-style plot should be used, and lwd = 3 sets the line width to 3 to make the plot more visible. The main, xlab, and ylab arguments specify the plot title, x-axis label, and y-axis label, respectively.

2. ppois() function in R

ppois() function is used to calculate the cumulative distribution function (CDF) for a Poisson distribution. It takes two arguments: the value at which to evaluate the CDF and the mean of the Poisson distribution.

For example, to calculate the CDF at x = 3 for a Poisson distribution with a mean of 2.5, you can use the following code:

ppois(3, 2.5)
# Plot CDF for Poisson distribution with mean of 2.5 for q = 0 to 10
q <- seq(0, 10, by = 1)
cdf <- ppois(q, 2.5)
plot(
q,
cdf,
type = "s",
lwd = 3,
main = "Poisson CDF",
xlab = "Number of events",
ylab = "Probability"
)


This will create a plot of the CDF for the Poisson distribution with a mean of 2.5, showing the probability of observing up to each number of events from 0 to 10. The type = "s" argument specifies that a step function plot should be used, and lwd = 3 sets the line width to 3 to make the plot more visible. The main, xlab, and ylab arguments specify the plot title, x-axis label, and y-axis label, respectively.

3. qpois() function in R

qpois() function is used to calculate the quantiles of a Poisson distribution. It takes two arguments: the probability at which to evaluate the quantile and the mean of the Poisson distribution.

For example, to calculate the 95th percentile of a Poisson distribution with a mean of 2.5, you can use the following code:

qpois(0.95, 2.5)
# Plot ICDF for Poisson distribution 
# with mean of 2.5 for p = 0.1 to 0.9
p <- seq(0.1, 0.9, by = 0.1)
icdf <- qpois(p, 2.5)
plot(
p,
icdf,
type = "o",
pch = 19,
lwd = 3,
main = "Poisson ICDF",
xlab = "Probability",
ylab = "Number of events"
)

This will create a plot of the ICDF for the Poisson distribution with a mean of 2.5, showing the smallest integer value of x for which the probability of observing up to x events is greater than or equal to each probability value from 0.1 to 0.9. The type = "o" argument specifies that a line and points plot should be used, and pch = 19 sets the point character to a solid circle. The lwd = 3 argument sets the line width to 3 to make the plot more visible. The main, xlab, and ylab arguments specify the plot title, x-axis label, and y-axis label, respectively.

4. qpois() function in R

rpois() function is used to generate random numbers from a Poisson distribution. It takes one argument: the mean of the Poisson distribution.

For example, to generate 10 random numbers from a Poisson distribution with a mean of 2.5, you can use the following code:

rpois(10, 2.5)
# Define the values for x
x <- 0:10

# Compute the Poisson probability mass function for mean 3
pmf <- dpois(x, lambda = 3)

# Plot the probability mass function
plot(
x,
pmf,
type = "h",
lwd = 2,
col = "blue",
xlab = "x",
ylab = "P(X = x)",
main = "Poisson PMF for lambda = 3"
)

# Add text labels to the plot
text(6, pmf[7], "P(X=6) = 0.050")

# Add vertical and horizontal lines to highlight the label
segments(6, 0, 6, pmf[7], lty = 2)
segments(0, pmf[7], 6, pmf[7], lty = 2)

This will create a plot that shows the Poisson probability mass function for a Poisson distribution with mean 3, as well as a label indicating the probability of observing x = 6.

 

These functions can be used to perform a variety of calculations and simulations involving Poisson distributions in R programming.

Compute Randomly Drawn Negative Binomial Density in R Programming

How to Use the Multinomial Distribution in R