I have two samples that I know a priori were drawn from the same distribution. When I increase the size of the samples, the K-S statistic dips significantly (expected), but so does the p-value, sometimes. It actually exhibits a kind of erratic behavior:
import numpy as np
from scipy.stats import norm, ks_2samp
np.random.seed(0)
for n in [10, 100, 1000, 10000, 100000, 1000000]:
x = norm(0, 4).rvs(n)
y = norm(0, 4).rvs(n)
print(ks_2samp(x, y))
result:
KstestResult(statistic=0.3, pvalue=0.7869297884777761)
KstestResult(statistic=0.09, pvalue=0.8154147124661313)
KstestResult(statistic=0.031, pvalue=0.7228251828701066)
KstestResult(statistic=0.0239, pvalue=0.0066097390500499155)
KstestResult(statistic=0.002950000000000008, pvalue=0.7757569319761763)
KstestResult(statistic=0.0011920000000000819, pvalue=0.4758505446766491)
why did the p-value drop between 2 and 3, and 3 and 4? and in the subsequent iteration, it surges up to 0.7, then drops again. why is that?
More generally, do I even need to look at p-value when interpreting the result of the K-S test? it sounds from the wikipedia article that the null hypothesis can be rejected based on the statistic alone.