The Suanshu Statistics Library supports the "Kolmogorov-Smirnov two-sample test" by rejecting the null hypothesis if $p$-value if smaller than significance level $alpha$ (e.g., $p<0.05$).

My question is whether there is any method to check if the "test statistic" exceeds the critical value (for $alpha = 0.05$) to reject the "null hypothesis" in Suanshu Library or any other statistics library?. If not, is there any formula to compute the critical values by ourself for two-sample K-Smirnov test to check against test statistic.

Any suggestions regarding this are welcome.

**Contents**hide

#### Best Answer

I am assuming you are asking because the Suanshu help page reports in reference to the K-S distribution, "This is not done yet." Luckily, it is very easy to do in R. If `x`

and `y`

are your two samples, `ks.test(x,y)`

returns the test statistic and pvalue. For example,

`> x <- rnorm(50) > y <- runif(30) > ks.test(x, y) Two-sample Kolmogorov-Smirnov test data: x and y D = 0.5, p-value = 9.065e-05 alternative hypothesis: two-sided `

By default, it will compute exact or asymptotic p-values based on the product of the sample sizes (exact p-values for `n.x*n.y < 10000`

in the two-sample case), or you can specify this option with a third argument, `exact=F`

or `exact=T`

. Exact p-values are calculated using the methods of Marsaglia, et al. (2003), which the Suanshu documentation also cites. Some large sample approximations are given here, although I don't have a proper citation. Lastly, if you don't want to install R, there are web calculators for the two-sample K-S test, although I don't know if they use the same algorithm as R because the one I found only reported three decimal points for the p-value.