This is the distribution of the maximum absolute differences between an
empirical distribution function, computed from n samples or observations,
and a comparison (or target) cumulative distribution function, which is
assumed to be continuous.
(The “two” in the name is because this is the two-sided difference.
ksone is the distribution of the positive differences, Dn+,
hence it concerns one-sided differences.
is the limiting
distribution of the maximum absolute differences .)
kstwobign
normalized
nDn
Writing Dn=supt∣Fempirical,n(t)−Ftarget(t)∣,
kstwo is the distribution of the Dn values.
kstwo can also be used with the differences between two empirical distribution functions,
for sets of observations with m and n samples respectively.
Writing Dm,n=supt∣F1,m(t)−F2,n(t)∣, where
F1,m and F2,n are the two empirical distribution functions, then
Pr(Dm,n≤x)≈Pr(DN≤x) under appropriate conditions,
where N=(m+nmn).
There is one shape parameter n, a positive integer, and the support is x∈[0,1].
The implementation follows Simard & L’Ecuyer, which combines exact algorithms of Durbin and Pomeranz
with asymptotic estimates of Li-Chien, Pelz and Good to compute the CDF with 5-15 accurate digits.
Examples
>>> importnumpyasnp>>> fromscipy.statsimportkstwo
Show the probability of a gap at least as big as 0, 0.5 and 1.0 for a sample of size 5
Durbin J. “The Probability that the Sample Distribution Function Lies Between Two
Parallel Straight Lines.” Ann. Math. Statist., 39 (1968) 39, 398-411.
Pomeranz J. “Exact Cumulative Distribution of the Kolmogorov-Smirnov Statistic for
Small Samples (Algorithm 487).” Communications of the ACM, 17(12), (1974) 703-704.
Li-Chien, C. “On the exact distribution of the statistics of A. N. Kolmogorov and
their asymptotic expansion.” Acta Matematica Sinica, 6, (1956) 55-81.
Pelz W, Good IJ. “Approximating the Lower Tail-areas of the Kolmogorov-Smirnov One-sample
Statistic.” Journal of the Royal Statistical Society, Series B, (1976) 38(2), 152-156.
Simard, R., L’Ecuyer, P. “Computing the Two-Sided Kolmogorov-Smirnov Distribution”,
Journal of Statistical Software, Vol 39, (2011) 11.