嗨,我有以下一组非标准化直方图的代码:
def vmag_hist_maxwell(vel_bin_size,vmag):
plt.ioff()
maxwell = stats.maxwell
params = maxwell.fit(vmag, floc=0)
max_bin = int(np.max(vmag)/vel_bin_size) + 2
bins_re= np.array([n*vel_bin_size for n in range(0,max_bin)])
xmax = 1000
plt.xlim(0,xmax)
n, bins, patches = plt.hist(vmag, bins_re, histtype = 'bar', facecolor='blue', normed = 1) #n = counts, bins = bin locations, patches = ?
bins_m = [(bins_re[i]+bins_re[i+1])/2.0 for i in range(0,len(bins_re)-1)]
y_fit = maxwell.pdf(bins_m, *params)
x_points = np.arange(0,xmax)
y_fit_smooth = maxwell.pdf(x_points, *params)
plt.plot(x_points, y_fit_smooth, lw=2, color = 'red')
chi_sq = stats.chisquare(n, y_fit)
plt.title("Velocity Histogram GB size %0.1f; chi_sq: %0.2e ; p_val: %0.2e ; vel_binwidth: %0.2s ; sigma: %0.1f" % (R, chi_sq[0], chi_sq[1],vel_bin_size, params[1]), size = 8) #Sets title
plt.xlabel("Velocity magnitude in km/s", size = 10) #Sets title
plt.ylabel("Normalized histogram with maxwellian fit", size = 10) #Sets title
filename = plot_file_loc+"velocity_fitted_hist_gb_"+str(int(R))+ "_vel_binwidth_"+ str(int(vel_bin_size)) +"_lasdamas" + ".png"
plt.savefig(filename , dpi=200)
plt.close()
这将生成以下绘图:
然后,我对上面显示的代码进行以下更改:
^{pr2}$这将生成以下图片:
这是取消直方图规格化并对非标准化直方图进行拟合的正确方法吗? 正如你所注意到的,卡方和p值已经发生了巨大的变化!这是意料之中的吗??在
谢谢!在
无法对您的代码进行评论,但它似乎有效。请注意,卡方拟合优度检验的目的是对每个箱子内的数据计数进行检验。实际上,不能在标准化值上使用它,或者与任何其他缩放一起使用。所以不管你展示什么,卡方必须基于实际计数。在
相关问题 更多 >
编程相关推荐