python-3.x - 为什么我不能使用卡方检验拟合泊松分布?装修有什么问题?
问题描述
我想检查一组数据点是否遵循泊松分布。为此,我首先使用 10 个 bin 绘制直方图并计算每个 bin 中的值。然后我尝试使用以下代码拟合泊松分布。最后我的卡方值太大了。我已经经历了几个例子,其中卡方值与卡方分布表进行比较是合理的。我的输入数据 x 已经标准化了用于绘制直方图的 256 个值。由于输入数据包含正值和负值。归一化后,我得到了合理的直方图形状,如附图所示。我真的很困惑为什么卡方值太大?如果我将值从 256 增加到 1000,直方图形状看起来仍然类似于泊松分布,但 chisqure 值也显示出大幅增加。我该如何解决这个问题?
`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`
解决方案
推荐阅读
- kotlin - Gradle - 尽管有大量内存,但运行测试时出现 OutOfMemoryError
- heroku - 请问我该如何解决这个问题?
- python - 如何在python中查看对等方的ssl证书
- excel - 选择时更改形状文本颜色
- angular - Angular 11在两个不相关的组件之间传递数据不起作用
- node.js - docker-compose:无法将本地模块添加到项目中,找不到 package.json 文件
- javascript - 当我尝试使用一个命令添加 2 个或更多角色时,它会删除它们
- html - 偏移 html 锚以调整固定标题 - Safari 上的不同 CSS
- angular - 将路由参数转换为可为空的数字
- postgresql - 插入操作不锁定 typeorm (postgresql)