# [Scipy-tickets] [SciPy] #395: kstest computes incorrect value

SciPy scipy-tickets@scipy....
Wed Nov 26 23:40:37 CST 2008

```#395: kstest computes incorrect value
-------------------------+--------------------------------------------------
Reporter:  peridot      |        Owner:  somebody
Type:  defect       |       Status:  new
Priority:  normal       |    Milestone:  0.7.0
Component:  scipy.stats  |      Version:
Severity:  normal       |   Resolution:
Keywords:               |
-------------------------+--------------------------------------------------
Changes (by josefpktd):

* type:  enhancement => defect

Comment:

Looking at this again, I'm quite sure the kstest is wrong.

The current implementation uses absolute value of the deviation, therefore
it is a two sided test, one-sided test takes either max or min deviation
(not absolute). However, the test distribution that is used to calculate
the p-value is ksone, the distribution for the one-sided Kolmogorov-
Smirnov test. So, the reported p-value should be off by approximately one
half, or maybe double (?).

The proposed correction, based on the numerical recipes, can improve the
power of the test, but might not be important for large samples.

Proposed change:

Add all 3 tests as in R, and put warning in doc string, that two-sided
test is based on asymptotic distribution and correct only for large
numbers.

Note: kstwobign (or special.kolmogorov) requires sqrt(n) correction
(convergence speed)

Then, if someone gets around, implement a correct implementation of the
2-sided K-S test distribution, as proposed in the mailing list discussion.

extra: compare with, check and vectorize ks_2samp

Reference:
Khamis H. J., The two-stage delta-corrected Kolmogorov-Smirnov test,
Journal of Applied Statistics, Volume 27, Number 4, 1 May 2000 , pp.
439-450(12)

I'm not a K-S, expert, but that's my conclusion, with the help of Google
and no statistics book at hand.

--
Ticket URL: <http://scipy.org/scipy/scipy/ticket/395#comment:5>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.
```