0

I Want to check whether a set of data points follow Poisson distribution or not. For this First I plot histogram using 10 bins and count values in each bin. Then I try to fit Poisson distribution using the following code. At the end my chisquare value is too large. I have gone through several examples in which chisquare value is reasonable to compare with chisquare distribution table. My input data x has normalized 256 values that I use to plot histogram. Since input data contains both positive and negative value. After normalizing I get reasonable shape of histogram as show in the attached figure. I'm really confused why chisquare value is too large? If I increase values from 256 to 1000 histogram shape still looks similar to Poisson distribution but chisqure value also shows a large increase. How can I fix this problem?

`x =np.array(flatten_list)
x = Ls_Store/Ls_Store.mean()
#Formula of Poisson distribution:
def Poisson_fit(mu,x):
    return (((mu**x) * np.exp(-mu))/math.factorial(x)) 

fig = plt.figure()
ax = fig.add_subplot(111)

hist,bins,patches=plt.hist(x,bins=10,label='h=5.0')
print("bin_counts: ",hist)
#bin_count: [94. 64. 32. 30. 16. 11.  3.  1.  3.  1.]

x_ = np.arange(len(hist))

fx = np.multiply(x_,hist)

mu = np.sum(fx)/np.sum(hist)
print("mu: ",mu)
#mu:  1.5490196078431373
result=[]
for k in range(len(x_)):
    result.append(Poisson_fit(mu,x_[k]))
result = np.array(result)
h = np.sum(hist)

#Counts in Poisson
m= h*result

#Implement Chisquare Test
f_obs =hist
f_exp= m
print("f_obs: ",f_obs)
print("f_exp: ",f_exp)
chisquare =[]
for h in range(len(f_obs)):
    chisquare.append(((f_obs[h]-f_exp[h])**2)/f_exp[h])
chisquare = np.array(chisquare)
print(np.sum(chisquare))
#394.74825860641397`
jerry
  • 385
  • 6
  • 18
  • I would recommend not posting the same question [over](https://stackoverflow.com/questions/56944665/chisquare-test-give-wrong-result-should-i-reject-proposed-distribution) and [over](https://stackoverflow.com/questions/56947157/how-to-check-goodness-of-fit-in-python-from-chisquare-function) again. It seems you have a problem with understanding statistics, so in that case a question at https://stats.stackexchange.com may make more sense. – ImportanceOfBeingErnest Jul 10 '19 at 12:20
  • But I have doubt may be there is something wrong in fitting function thats why I posted this question. I tried to figure it out but could not fix it. – jerry Jul 10 '19 at 12:23

0 Answers0