This article about R’s rpois function is part of a series about generating random numbers using R. The rpois function can be used to simulate the Poisson distribution. It is commonly used to model the number of expected events concurring within a specific time window.

Our earlier articles in this series dealt with:

- random selections from lists of discrete values
- Simulating the uniform distributions
- Simulating a normal distribution
- Binomial trials
- The exponential distribution

### R and the Poisson Distribution

We’re going to start by introducing the rpois function and then discuss how to use it.

The Poisson distribution is commonly used to model the number of expected events for a process given we know the average rate at which events occur during a given unit of time. For example, let us assume that 10 shoppers enter a store per minute.

Can we generate a simulation of the number of customers per minute for the next 10 minutes?

We describe the process as:

- A window of observation – a specific time period in which events can occur
- A rate of occurrence – how often is an event expected to occur in that window
- The number of times an event occurs (the observation)

R’s rpois function generates values from the Poisson distribution and returns the results. The function takes two arguments:

- Number of observations you want to see
- The estimated rate of events for the distribution; this is expressed as average events per period

The expected syntax is:

rexp(# observations, rate=rate )

Continuing our example from above:

rpois(10, 10) [1] 6 10 11 3 10 7 7 8 14 12

As you can see, there is some variation in the customer volume. A couple of minutes have seven or eight. One has 6. And apparently there was a mad dash of 14 customers as some point. The Poisson distribution models this type of variation in the expected throughput of a process.

### Practical Applications of A Poisson Distribution

The Poisson distribution is commonly used within industry and the sciences.

The classical example of the Poisson distribution is the number of Prussian soldiers accidentally killed by horse-kick, due to being the first example of the Poisson distribution’s application to a real-world large data set. Ten army corps were observed over 20 years, for a total of 200 observations, and 122 soldiers were killed by horse-kick over that time period. The question is how many deaths would be expected over a period of a year, which turns out to be excellently modeled by the Poisson distribution.

Some other examples:

- number of equipment failures per day for logistics company
- number of customers arriving at a retailer
- the number of visitors to a web site
- number of inbound phone calls
- number of customer complaints