This document includes the mathematical and statistical expressions and for the run-through of the R function that I use for my page: https://dataz4s.com/statistics/poisson-distribution/

\[X \sim B(n=60; p = \frac{11}{60} = 0.183)\]

\[\Leftrightarrow X \sim B(60; 0.183)\]

\[P(k) = \binom{60}{k}\times 0.183^{k} \times (1-0.183)^{60-k} \]

\[P(k) = \binom{3600}{k}\times 0.183^{k} \times (1-0.183)^{3600-k} \]

\[P(k) = \binom{7200}{k}\times 0.183^{k} \times (1-0.183)^{7200-k} \]

\[p(x) = \frac{\lambda^x e^{-\lambda}}{x!}\]

\[\mu = \lambda\]

\[Q^2 = \lambda\]

\[\lambda = \text{mean of number of times that the event occurs in the interval}\] \[e= \text {the base of the natural logarithm} = 2.718281828\]

\[X\sim P(\lambda)\]

\[X\sim Poisson(\lambda)\]

\[X = \text{Number of sales per opening hour}\] \[X\sim P(\lambda = 2.1)\]

\[p(x) = \frac{\lambda^x e^{-\lambda}}{x!}\Leftrightarrow\] \[p(0) = \frac{2.1^0 e^{-2.1}}{0!}=0.122\] \[p(1) = \frac{2.1^1 e^{-2.1}}{1!}=0.257\] \[p(2) = \frac{2.1^2 e^{-2.1}}{2!}=0.270\] \[p(3) = \frac{2.1^3 e^{-2.1}}{3!}=0.189\] \[p(4) = \frac{2.1^4 e^{-2.1}}{4!}=0.099\]

Here a summary of how to apply the dpois, ppois, rpois and the qpois functions in R:

For the dpois and ppois function I use the Mike Marinโs 4 minutes tutorial video: https://www.youtube.com/watch?v=778WK1Pf8eI&feature=youtu.be.

For the rpois and qpois, I follow the examples from http://www.programmingr.com/

The dpois function **finds values for the probability density function of X, f(x)** X follows a Poisson distribution with a known rate of \(\lambda\)=7: \[X\sim Poisson(\lambda=7)\]

```
# P(X=4)
dpois(x=4, lambda = 7)
```

`## [1] 0.09122619`

```
# P(X=0) & P(X=1) &...& P(X=4)
dpois(x=0:4, lambda=7)
```

`## [1] 0.000911882 0.006383174 0.022341108 0.052129252 0.091226192`

```
# P(X <= 4)
# this can be done with dpois:
sum( dpois(x=0:4, lambda=7) )
```

`## [1] 0.1729916`

and it can be done with the ppois function:

The ppois function returns probabilities associated with the probability distribution function, F(x)

```
# P(X <= 4)
ppois(q=4, lambda = 7, lower.tail = T)
```

`## [1] 0.1729916`

```
# P(X >= 12)
ppois(q=12, lambda = 7, lower.tail = F)
```

`## [1] 0.02699977`

The rpois function takes a random sample from a Poisson distribution and be applied for as for modelling the number of expected events occurring within a determined time interval:

```
# Say that we wish to take a random sample of 10 from a Poisson distribution with a known rate of lambda = 7. It could be that we have observed a number of 7 customers entering a shop per minute and that we wish to generate a sumulation of the number of customers per minute for the next 10 minutes:
rpois(10,7)
```

`## [1] 5 11 5 8 3 11 8 7 5 7`

Our sample shows 10 customers the first minute, 5 customers the second, 3 the thir, 5 the fourth and so on. The variaion in the expected numbers are modeled by the Poisson distribution.

The qpois function finds quantiles for the Poisson distribution. As such, it is the inverse of the operation performed by **ppois**. We percentile and it generates the number of events associated with that cumulative probability:

`qpois(0.25,7)`

`## [1] 5`

We have observed an average sale of 2.1 per opening hour, \(X\sim Poisson(\lambda=2.1)\).

Question 1: What are the different probabilities of selling one, two, three or four during the next opening hour?

```
# Q1: Selling between 0, 1, 2, 3 or 4:
dpois(x=0:4, lambda=2.1)
```

`## [1] 0.12245643 0.25715850 0.27001642 0.18901150 0.09923104`

Question 2: What is the probability of doing between 0 and 4 sales during the next opening hour?

```
# Q2: Selling between 0 and 4:
ppois(q=4, lambda = 2.1, lower.tail = T)
```

`## [1] 0.9378739`

`sum( dpois(x=0:4, lambda=2.1) )`

`## [1] 0.9378739`