# Kolmogorov distribution

Is there a package in R for the Kolmogorov distribution which allows me to plot density, distribution, calculates quantiles, etc.?

The Kolmogorov distribution arises from $K=\sup|B|$, where $B$ is a Brownian bridge. Its values are usually tabulated, so I thought it would have its own function in R, like the normal distribution.

It seems ks.test() uses this for cdf:

 pkolmogorov1x <- function(x, n) {
if (x <= 0)
return(0)
if (x >= 1)
return(1)
j <- seq.int(from = 0, to = floor(n * (1 -
x)))
1 - x * sum(exp(lchoose(n, j) + (n - j) * log(1 -
x - j/n) + (j - 1) * log(x + j/n)))
}

• What do you mean by the Kolmogorov distribution here? – Nick Cox Sep 2 '14 at 19:20
• You may also find this of interest. – gung - Reinstate Monica Sep 2 '14 at 19:28
• Someone made a package called kolmin but "package ‘kolmin’ is not available (for R version 3.3.0)" – user3083324 Jun 18 '16 at 20:10
• – kjetil b halvorsen Aug 17 '17 at 20:03

The expression for the Kolmogorov-Smirnov CDF is provided in the wikipedia link:

http://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test#Kolmogorov_distribution

Kolmogorov distribution

The Kolmogorov distribution is the distribution of the random variable $K=\sup_{t\in[0,1]}|B(t)|$ where $B(t)$ is the Brownian bridge. The cumulative distribution function of $K$ is given by $\operatorname{Pr}(K\leq x)=1-2\sum_{k=1}^\infty (-1)^{k-1} e^{-2k^2 x^2}=\frac{\sqrt{2\pi}}{x}\sum_{k=1}^\infty e^{-(2k-1)^2\pi^2/(8x^2)}.$

Note that this distribution arises as an asymptotic result, detailed in the same link.

• Yeah well, so you are suggesting I use the analytical expression for computations? furthermore that's only the cdf. – user3083324 Sep 4 '14 at 2:25
• Can anyone help me? – user3083324 Oct 2 '14 at 2:29
• (1) This CDF is easily differentiated to produce the PDF. (2) The series converges very rapidly and therefore is readily calculated. (3) For small samples, where this asymptotic result might not be accurate, the Wikipedia reference to Marsaglia, Tsang, and Wang begins with an account of "a method that expresses the required probability as a certain element in the nth power of an easily formed matrix." – whuber Oct 2 '14 at 14:33
• @whuber I see your point, but it seems R uses another expression for computation. – user3083324 Oct 4 '14 at 0:38