Discrete Distribution Functions

  • Binomial distribution
  • Poisson distribution (PMF, CDF, and PPF)

Author: Thomas Haslwanter, Feb-2017

In [7]:
# Note: here I use the modular approach, which is more appropriate for scripts
# "%pylab inline" also loads numpy as np, and matplotlib.pyplot as plt
%pylab inline
import scipy.stats as stats
Populating the interactive namespace from numpy and matplotlib

Binomial Distribution

In [8]:
bd1 = stats.binom(20, 0.5)
bd2 = stats.binom(20, 0.7)
bd3 = stats.binom(40, 0.5)
k = arange(40)
plot(k, bd1.pmf(k), 'o-b')
plot(k, bd2.pmf(k), 'd-r')
plot(k, bd3.pmf(k), 's-g')
title('Binomial distribition')
legend(['p=0.5 and n=20', 'p=0.7 and n=20', 'p=0.5 and n=40'])
xlabel('X')
ylabel('P(X)')
Out[8]:
<matplotlib.text.Text at 0x2011c861ac8>

Poisson Distribution

In [9]:
pd = stats.poisson(10)
plot(k, pd.pmf(k),'x-')
title('Poisson distribition - PMF')
xlabel('X')
ylabel('P(X)')
Out[9]:
<matplotlib.text.Text at 0x2011dcb3908>

Different Views of the Poisson Distrubution

In [10]:
k = arange(30)
plot(k, pd.cdf(k))
title('Poisson distribition - CDF')
xlabel('X')
ylabel('P(X)')
Out[10]:
<matplotlib.text.Text at 0x2011dd74ef0>
In [11]:
y = linspace(0,1,100)
plot(y, pd.ppf(y))
title('Poisson distribition - PPF')
xlabel('X')
ylabel('P(X)')
Out[11]:
<matplotlib.text.Text at 0x2011dd799e8>