Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Poisson Functions in R Programming

  • Last Updated : 05 Oct, 2021

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 language with the help of R’s inbuilt functions.
There are four Poisson functions available in R: 
 

  • dpois
  • ppois
  • qpois
  • rpois

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

dpois()

This function is used for 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: 
dpois(k, \lambda, log)
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

Example: 
 



Python3




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

Output: 
 

[1] 0.2240418

[1] 0.1606231

 

ppois()

This function is used for the illustration of 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: 
ppois(q, \lambda, lower.tail, log)
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

Example: 
 

Python3




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

Output: 
 



[1] 0.4231901
[1] 0.6063028

 

rpois()

The function rpois() is used for generating random numbers from a given Poisson’s distribution.
Syntax: 
rpois(q, \lambda)
where, 
 

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

Example: 
 

Python3




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

Output: 
 

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

 

qpois()

The function qpois() is used for generating 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: 
qpois(q, \lambda, lower.tail, log)
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

Example: 
 

Python3




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

Output: 
 

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

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :