*52*

This tutorial explains how to work with the Poisson distribution in R using the following functions

**dpois**: returns the value of the Poisson probability density function.**ppois**: returns the value of the Poisson cumulative density function.**qpois**: returns the value of the inverse Poisson cumulative density function.**rpois**:Â generates a vector of Poisson distributed random variables.

Here are some examples of cases where you might use each of these functions.

**dpois**

TheÂ **dpoisÂ **functionÂ finds the probability that a certain number of successes occur based on an average rate of success, using the following syntax:

**dpois(x,Â lambda)Â **

where:

**x:Â**number of successes**lambda:Â**average rate of success

Hereâ€™s an example of when you might use this function in practice:

**It is known that a certain website makes 10 sales per hour. In a given hour, what is the probability that the site makes exactly 8 sales?**

dpois(x=8, lambda=10) #0.112599

The probability that the site makes exactly 8 sales isÂ **0.112599**.

**ppois**

The **p****poisÂ **functionÂ finds the probability that a certain number of successes *or less* occur based on an average rate of success, using the following syntax:

**ppois(q,Â lambda)Â **

where:

**q:Â**number of successes**lambda:Â**average rate of success

Hereâ€™s are a couple examples of when you might use this function in practice:

**It is known that a certain website makes 10 sales per hour. In a given hour, what is the probability that the site makes 8 sales or less?**

ppois(q=8, lambda=10) #0.3328197

The probability that the site makes 8 sales or less in a given hour isÂ **0.3328197**.

**It is known that a certain website makes 10 sales per hour. In a given hour, what is the probability that the site makes more than 8 sales?**

1 - ppois(q=8, lambda=10) #0.6671803

The probability that the site makes more than 8 sales in a given hour isÂ **0.6671803**.

**qpois**

The **q****poisÂ **functionÂ finds the number of successes that corresponds to a certain percentile based on an average rate of success, using the following syntax:

**qpois(p,Â lambda)Â **

where:

**p:Â**percentile**lambda:Â**average rate of success

Hereâ€™s an example of when you might use this function in practice:

**It is known that a certain website makes 10 sales per hour. How many sales would the site need to make to be at the 90th percentile for sales in an hour?**

qpois(p=.90, lambda=10) #14

A site would need to makeÂ **14Â **sales to be at the 90th percentile for number of sales in an hour.

**rpois**

The **r****poisÂ **function generates a list of random variables that follow a Poisson distribution with a certain average rate of success, using the following syntax:

**rpois(n,Â lambda)Â **

where:

**n:Â**number of random variables to generate**lambda:Â**average rate of success

Hereâ€™s an example of when you might use this function in practice:

**Generate a list of 15 random variables that follow a Poisson distribution with a rate of success equal to 10.**

rpois(n=15, lambda=10) # [1] 13 8 8 20 8 10 8 10 13 10 12 8 10 10 6

Since these numbers are generated randomly, theÂ **rpois()Â **function will produce different numbers each time. If you want to create a reproducible example, be sure to use theÂ **set.seed()Â **command.