Open In App

Poisson Functions in R Programming

Improve
Improve
Like Article
Like
Save
Share
Report

The Poisson distribution represents the probability of a provided number of cases happening in a set period of space or time if these cases happen with an identified constant mean rate (free of the period since the ultimate event). Poisson distribution has been named after Siméon Denis Poisson(French Mathematician).  

Many probability distributions can be easily implemented in R Programming Language with the help of R’s inbuilt functions. There are four Poisson functions available in R:

  • dpois
  • ppois
  • qpois
  • rpois

What is Poisson Distribution?

Consider a Random Variable X with Poisson distribution given as [Tex]X \sim \Poisson \lambda.  [/Tex]The mean [Tex](\mu)  [/Tex]of this distribution is given by [Tex]\mu= \lambda.  [/Tex]The variance of such a distribution is [Tex]\sigma^{2}=\lambda.  [/Tex]So if there are ‘n’ which happened out of which the only k were successful when the probability of success is very less [Tex](\frac{\lambda}{n})  [/Tex]then the probability of success becomes

[Tex]P(X=k)= \frac{e^{-\lambda}\lambda^{k}}{k!}  [/Tex] 

Poisson Probability Mass Function – dpois()

This function is used for the illustration of Poisson density in an R plot. The function dpois() calculates the probability of a random variable that is available within a certain range.

Syntax: 

[Tex]dpois(k, \lambda, log)  [/Tex]

where, 

  •  K: number of successful events happened in an interval 
  • lambda: mean per interval 
  • log: If TRUE then the function returns probability in form of log 

R

dpois(2, 3)
dpois(6, 6)

Output: 

[1] 0.2240418 [1] 0.1606231

Poisson Distribution – ppois()

This function is used for the illustration of the cumulative probability function in an R plot. The function ppois() calculates the probability of a random variable that will be equal to or less than a number.


Syntax: 

[Tex]ppois(q, \lambda, lower.tail, log)  [/Tex]

where, 

  • K: number of successful events happened in an interval 
  • lambda: mean per interval 
  • lower.tail: If TRUE then left tail is considered otherwise if the FALSE right tail is considered 
  • log: If TRUE then the function returns probability in form of log 

R

ppois(2, 3)
ppois(6, 6)

Output:

[1] 0.4231901 [1] 0.6063028

Poisson pseudorandom – rpois()

The function rpois() is used for generating random numbers from a given Poisson distribution.

Syntax: 

[Tex]rpois(q, \lambda)  [/Tex]

where, 

  • q: number of random numbers needed 
  • lambda: mean per interval

R

rpois(2, 3)
rpois(6, 6)

Output: 

[1] 2 3 [1] 6 7 6 10 9 4

Poisson Quantile Function – qpois()

The function qpois() is used for generating the quantile of a given Poisson’s distribution. In probability, quantiles are marked points that divide the graph of a probability distribution into intervals (continuous ) which have equal probabilities.

Syntax: 

[Tex]qpois(q, \lambda, lower.tail, log)  [/Tex]

where, 

  • K: number of successful events happened in an interval 
  • lambda: mean per interval 
  • lower.tail: If TRUE then left tail is considered otherwise if the FALSE right tail is considered 
  • log: If TRUE then the function returns probability in form of log

R

y <- c(.01, .05, .1, .2)
qpois(y, 2)
qpois(y, 6)

Output: 

[1] 0 0 0 1 [1] 1 2 3 4



Last Updated : 11 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads