# How can I get the critical values of the Kolmogorov-Smirnov statistic test?

I would like to calculate critical values for the Kolmogorov-Smirnov test statistic for the Weibull distribution. Can someone help me to do that?

• Please provide a minimal working example that describes your problem, or demonstrates your research into the issue and what you have tried so far. Commented Sep 7, 2015 at 20:10
• At what confidence level? Is the sample size large or small? Are you interested in an exact result, or will bootstrap Monte-Carlo approximation be sufficient? Commented Sep 7, 2015 at 20:19

The Kolmogorov-Smirnov test is used to test for the equality of an empirical and a theoretical distribution. The critical value is not specific to a certain distribution and, for sufficiently large samples, can be calculated as follows (see Wikipedia):

pr[x_] := (Sqrt[2*Pi]/x)*Sum[E^((-(2*k - 1)^2)*(Pi^2/(8*x^2))), {k, 1, 100}]

crit[α_, n_] := (x /. FindRoot[pr[x] == 1 - α, {x, 0.5}])/Sqrt[n]


where n is the the number of data points and α the rejection level.

Actually, the sum in pr should run to infinity, but 100 is sufficient for all means and purposes.

Note that the K-S test can be easily misused. It is meant for continuously distributed data and therefore should not be used for data that contains many ties (i.e., data sets with the kind of values you get when you're binning data).

If you are comparing two empirical distributions crit should be changed to

crit[α_, n1_, n2_] := (x /. FindRoot[pr[x] == 1 - α, {x, 0.5}])*Sqrt[(n1 + n2)/(n1*n2)]


where n1 and n2 are the number of data points in both data sets respectively.

Please note that Mathematica has a built-in KolmogorovSmirnovTest.

• BTW, Sum[E^((-(2*k - 1)^2)*(Pi^2/(8*x^2))), {k, 1, Infinity}] does evaluate symbolically. Did you try it? Or is there a problem with the sum it computes? Commented Sep 8, 2015 at 15:15
• @MichaelE2 I don't recall whether I tried it. I know I encountered this expression before and the guy there just summed to 100. I wonder why Wikipedia doesn't have the symbolic result when it is so easy to get. Commented Sep 8, 2015 at 16:40
• @MichaelE2 I now see that the result is in terms of EllipticTheta which itself is an infinite sum. No wonder that this is not given as a closed form solution in Wikipedia. BTW I examined the terms of the sum and it looks like only max two terms are ever necessary. Commented Sep 8, 2015 at 20:22
• I expect that everyone tends to think of theta functions as sums, but in some sense, any analytic function is an infinite sum. I also expect that very few computer systems have theta functions available in their programming environments, so it's not a widely useful observation. And then on top of that, given your observation that only a few terms are needed in practice, the practical people will think theta functions are an unnecessary complication. Commented Sep 8, 2015 at 20:56
• @Michael and Sjoerd: actually... the associated CDF being expressible as a theta function is a Good Thing; the methods used for numerical evaluation (e.g. modular transformations, Poisson summation) will tend to be a bit more efficient than straightforward summation. Commented Oct 7, 2015 at 0:17