While working with Andrew and a student from Dauphine on importance sampling, we wanted to assess the distribution of the resulting sample via the Kolmogorov-Smirnov measure
where F is the target. This distance (times √n) has an asymptotic distribution that does not depend on n, called the Kolmogorov distribution. After searching for a little while, we could not figure where this distribution was available in R. It had to, since ks.test was returning a p-value. Hopefully correct! So I looked into the ks.test function, which happens not to be entirely programmed in C, and found the line
[sourcecode language=”r” gutter=”false”]
PVAL <- 1 – if (alternative == "two.sided")
.Call(C_pKolmogorov2x, STATISTIC, n)
[/sourcecode]
which means that the Kolmogorov distribution is coded as a C function C_pKolmogorov2x in R. However, I could not call the function myself.
[sourcecode language=”r” gutter=”false”]
> .Call(C_pKolmogorov2x,.3,4)
Error: object ‘C_pKolmogorov2x’ not found
[/sourcecode]
Hence, as I did not want to recode this distribution cdf, I posted the question on stackoverflow (long time no see!) and got a reply almost immediately as to use the package kolmim. Followed by the extra comment from the same person that calling the C code only required to add the path to its name, as in
[sourcecode language=”r” gutter=”false”]
> .Call(stats:::C_pKolmogorov2x,STAT=.3,n=4)
[1] 0.2292
[/sourcecode]