logo4 Evolution is progress—                          
progress is creativity.        
vline

Poisson Distribution

view blog view wiki view wiki view wiki

Though this article tackles Poisson distribution, a type of discrete probability distribution, it is rather focused on practical questions how to use matplotlib to construct graphs of that distribution.

Numpy offers three parameters that effect graphical appearance:

parametermeaningusage
mushape parameteressential, to construct a probability distribution
locoriginoptional, the origin of the probability distribution default = 0
sizevector lengthoptional, size of the one dimensional array of random variables default=0 => no array but a single random variable is returned
def set_figure(fig):    
   import numpy as np
   from scipy.stats import poisson
   ax=fig.add_subplot(3,1,1)
   bx=fig.add_subplot(3,1,2)
   cx=fig.add_subplot(3,1,3)
   fig.subplots_adjust(hspace=.5)

   p = [1, 3, 5, 10]
   c = ['r','b','y','g']
   shift = [0, 0.1, 0.2, 0.3]
   n = 30
   
   x = np.arange(-1,20+1,1)
   for i in range(4):
       rv = poisson(p[i])
       ax.vlines(x+shift[i], 0, rv.pmf(x), lw=2, color=c[i])

   ax.set_ylabel("Probability")
   ax.set_title("Poisson probability mass funtion")
   
   for i in range(4):
       rv = poisson(p[i])
       bx.vlines(x+shift[i], 0, rv.cdf(x), lw=2, color=c[i])
   
   bx.set_title("Poisson cumulative probability density funtion")
   
   size = 100
   R = []
   for i in range(4):
       R.append(poisson.rvs(p[i], size=size))

   string = ''
   j, k = 0, 0
   line = 1
   for i in range(4):
       for r in R[i]:
           j = j + 1
           string = string + str(r) + ','
           if k >= 49 or j == size:
               line = line - 0.06
               cx.text(0.05,line,string,color=c[i],size='5')
               string = ''
               k = 0
               
           else:
               k = k + 1
Binomial Distribution

The probability mass function can be written:

f(x) = \Bigl\{_\textrm{elsewhere}^{{{m^x e^{-m} } \over {x! }}\; x= 1,2,3, \cdots}

The cumulative probability function can be described by the equation:

F(x) = \sum_{k=0}^{x}{{m^k e^{-k} } \over {k! } }

The function of the Numpy parameters can be tested by the following sage cell.


Tags: Software Statistics


Categories: Mathematics Software

 
   

(c) Mato Nagel, Weißwasser 2004-2013, Disclaimer