Wednesday, April 3, 2019

The reproductive property of poisson distribution

In this article, first of all I'll introduce "sum of discrete probability variable" in general. Subsequently, withusing that, I'll show "The reproductive property of poisson distribution" . At the last I'll confirm these property with Python implementation! I'll be glad if you get some kick out of it :)

0. Sum of probability variable in general

In the beginning, I'll write about "Sum of probability variablt in general". Let $X$ and $Y$ be discrete probability variable, $Z$ is sum of $X$ and $Y$ like $Z = X+Y$. The probability mass function of $Z$ would be,

$$\begin{eqnarray}p(Z = z) &=& p(X+Y = z) \\ &=& \sum_t p(X = t) p(Y = Z -t)\end{eqnarray}$$

Actually it's convolution of two distribution. For all value on $X+Y=Z$, the joint distribution is summed up as following.

1. Sum of probability variable in poisson distribution

Let's say X and Y follows poisson distribution with mean of $\lambda$ and $\mu$ respectibely. Then probability mass function $p(Z)$ ($Z = X+Y$) can be derive as below.

Interestingly, probability mass function of $Z$ is poisson distribution again! On top of that, mean which govern poisson distribution is $\lambda + \mu$ :) Sometimes it's called "The reproductive property of poisson distribution".

2. Implementation with Python

Thankfully, we have computer in this era. We can confirm the reproductive property of poisson distribution and the parameter of distribution of Z. Let's say there are two poisson distribution, one has parameter of 2, the other has 5. They looks like the following.

In [1]:
from scipy.stats import poisson
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
lam = 2 
mu = 5

x = np.arange(0,20,1)

# plot two different distriobution
plt.figure(figsize=(13,5))
plt.subplot(1,2,1)
plt.bar(x, poisson.pmf(x,mu=lam))
plt.title('Poisson distribution with lambda = {}'.format(lam))
plt.subplot(1,2,2)
plt.bar(x, poisson.pmf(x,mu=mu))
plt.title('Poisson distribution with lambda = {}'.format(mu))
plt.show()

Now is the time to compute convolution of two different poisson distribution. Then we can compare our expected result and poisson distribution. It's amusing and enjoyable :)

In [3]:
# numpy to store the probability of Z
z_prob = np.empty(x.shape[0])

for i, z in enumerate(range(x.shape[0])):
    
    # Compute convolution then sum it up!
    z_prob[i] = np.array(
            [
                poisson.pmf(t,mu=lam) * poisson.pmf(z - t,mu=mu) 
                for t 
                in range(z+1)
            ]
        ).sum()

# plot the result of  convolution
plt.figure(figsize=(13,5))
# convolution
plt.subplot(1,2,1)
plt.bar(x,z_prob)
plt.title('Convolution of poisson with parameter = 2 and 5')
# poisson with  mu = lam + mu = 7
plt.subplot(1,2,2)
plt.bar(x,poisson.pmf(x,mu=7))
plt.title('Poisson distribution with lambda = 7')
plt.show()

Awesome! As we expected, they look same :)