So I was transforming data for machine learning purposes and checking whether I should use the data or log-transform it. In addition to creating histograms I decided to test for normality using scipy.stats.normaltest
. The data looks as follows.
The result of the normality test for this particular data was that the p-value=0.73
. Now, I don't claim to be a statistician. However... This does not look like a normal distribution. I tested with a np.random.normal(0, 1, size=1000)
and it gave something along the lines of p=0.2
and increasing it to a hundred thousand points gave p=0.6
. My data holds ~4000 records.
So I must ask. Have I missed something here? Some of the other vaguely log-normally distributed variables gave p-values
of the order 10^-20
after transforming. Does the value of the Chi^2 test need to be incorporated in some manner?
I'm really lost.
Edit:
Running the normaltest
on the whole DataFrame
gives different results, which adds to the confusion. It gives the same Chi^2 value, but a halved p-value
of 0.365...
Edit II
Just for the heck of it, this data gives a similar graph but a p-value
of 0.97. What.
>>> a = np.sort(df['col'].values).tolist()[::10]
[0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.1622, 0.1622, 0.1622, 0.1622, 0.1622, 0.1622, 0.1622, 0.1622, 0.1622, 0.1687, 0.1687, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.1729, 0.2005, 0.2216, 0.2216, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.2498, 0.3143, 0.3143, 0.3143, 0.3143, 0.3143, 0.3143, 0.3143, 0.48, 0.4854, 0.4854, 0.4854, 0.4854, 0.4854, 0.4854, 0.4854, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5078, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.5328, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.6496, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.9119, 0.912, 0.912, 0.912, 0.912, 0.912, 0.912, 0.912, 0.912, 0.912, 0.912, 0.912]
>>> from scipy.stats import normaltest
>>> normaltest(a)
NormaltestResult(statistic=0.05292848970575527, pvalue=0.9738828645381232)
>>> from matplotlib import pyplot as plt
>>> plt.hist(a) # Results in a similar graph to above
np.hstack([np.full(c, i) for i, c in enumerate([128, 0, 58, 7, 0, 41, 16, 0, 0, 167])])
, which just scales everything up and rounds. Either the skewness and kurtosis tests used here are surprisingly bad in this case, or there's a bug inscipy.stats
; it seems that you're calling the function correctly. $\endgroup$