且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

python中分布的正态性检验

更新时间:2022-02-16 01:17:31

这个问题 解释了为什么您得到如此小的 p 值.从本质上讲,正态性检验几乎总是在非常大的样本量上拒绝空值(例如,在您的样本中,您只能看到左侧有一些偏斜,这在您的大样本量下已经绰绰有余了).

This question explains why you're getting such a small p-value. Essentially, normality tests almost always reject the null on very large sample sizes (in yours, for example, you can see just some skew in the left side, which at your enormous sample size is way more than enough).

在您的情况下更实用的是绘制适合您数据的正态曲线.然后您可以看到正态曲线实际上有何不同(例如,您可以看到左侧的尾巴是否确实走得太长).例如:

What would be much more practically useful in your case is to plot a normal curve fit to your data. Then you can see how the normal curve actually differs (for example, you can see whether the tail on the left side does indeed go too long). For example:

from matplotlib import pyplot as plt
import matplotlib.mlab as mlab

n, bins, patches = plt.hist(array, 50, normed=1)
mu = np.mean(array)
sigma = np.std(array)
plt.plot(bins, mlab.normpdf(bins, mu, sigma))

(注意 normed=1 参数:这确保直方图被归一化为总面积为 1,这使其与正态分布等密度相当).

(Note the normed=1 argument: this ensures that the histogram is normalized to have a total area of 1, which makes it comparable to a density like the normal distribution).