Kolmogorov–Smirnov检验(stats.kstest)中P值与检验统计量不匹配问题
Your observation is correct and expected—here's the key reason:
You're generating data from the exact distribution you're testing against (standard normal) in every iteration. When the null hypothesis (H₀: data comes from the specified distribution) is true, p-values from valid hypothesis tests like the Kolmogorov–Smirnov test will always follow a uniform distribution over [0, 1].
Breakdown of Your Results:
- Your critical statistic check shows ~5% of test statistics exceed the α=0.05 threshold. This directly maps to ~5% of p-values being below 0.05 (the rejection region), which aligns perfectly with the uniform distribution (5% of values fall in the bottom 5th percentile).
- The rest of the p-values are evenly spread between 0 and 1 because, when H₀ holds, there's no systematic tendency for the test statistic to be large or small—each p-value between 0 and 1 is equally likely.
What If H₀ Was False?
If you generated data from a different distribution (e.g., stats.uniform.rvs), the p-values would cluster near 0, since the test statistic would frequently be large enough to reject H₀.
Confirm With Your Output
Look at the fraction below pvalue 0.05 printout—it should be ~0.05, which matches both your critical statistic result and the uniform distribution expectation. This confirms scipy.stats.kstest is working correctly.
内容的提问来源于stack exchange,提问作者BigGulpshuh

