To fit poisson distribution for the given frequencey distribution
Python
The Poisson distribution is the discrete probability distribution of the number of events occurring in a given time period, given the average number of times the event occurs over that time period.
Conditions for Poisson Distribution:
- An event can occur any number of times during a time period.
- Events occur independently. I
- The rate of occurrence is constant.
- The probability of an event occurring is proportional to the length of the time period.
# Developed by
# Register Number: DurgaDevi P
# Name: 212220230015
import numpy as np
import math
import scipy.stats
X=[0,1,2,3,4,5,6]
f=[153,169,72,31,12,6,2]
n=6
N=np.sum(f)
mean=np.inner(X,f)/N
Prob=list(); E=list(); xi=list()
print(" X P(X=x) Obs.Fr Ex.Fre xi ")
print("----------------------------------")
for x in range(7):
Prob.append(math.exp(-mean)*mean**x/math.factorial(x))
E.append(Prob[x]*N)
xi.append((f[x]-E[x])**2/E[x])
print("%2.2f %2.2f %4.2f %3.2f %3.2f"%(x,Prob[x],f[x],E[x],xi[x]))
print("----------------------------------")
cal_chi2=np.sum(xi)
print("Calculated value of Chi square is %4.2f"%cal_chi2)
tab_chi2=scipy.stats.chi2.ppf(1-.01, df=n)
print("Table value of Chi square at 1 level is %4.2f"%tab_chi2)
if cal_chi2<tab_chi2:
print("The given data can be fitted in Poissson distribution at 1% LOS")
else:
print("The given data cannot be fitted in Poisson distribution at 1% LOS")
Thus, fitting poisson distribution for the given frequencey distribution is verified.