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) 
                  if (x >= 1) 
                  j <- seq.int(from = 0, to = floor(n * (1 - 
                  1 - x * sum(exp(lchoose(n, j) + (n - j) * log(1 - 
                    x - j/n) + (j - 1) * log(x + j/n)))
| cite | improve this question | | | | |

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


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.

| cite | improve this answer | | | | |
  • $\begingroup$ Yeah well, so you are suggesting I use the analytical expression for computations? furthermore that's only the cdf. $\endgroup$ – user3083324 Sep 4 '14 at 2:25
  • $\begingroup$ Can anyone help me? $\endgroup$ – user3083324 Oct 2 '14 at 2:29
  • 1
    $\begingroup$ (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." $\endgroup$ – whuber Oct 2 '14 at 14:33
  • $\begingroup$ @whuber I see your point, but it seems R uses another expression for computation. $\endgroup$ – user3083324 Oct 4 '14 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.