Search code examples
rcomplexity-theory

Where can I find the limiting distribution of the Kolmogorov-Smirnov distance in R?


While doing an experiment on importance sampling, I simulate values of Kolmogorov-Smirnov distances

Dn = maxx |Fn(x)-F(x)|

where n is the size of the original importance sample and I want to compare those values to the asymptotic distribution of the Kolmogorov-Smirnov test, or Kolmogorov distribution, i.e.

Vn Dn ---> sup0<t<1|B(t)|

where B is the Brownian bridge.

Since ks.test relies on this asymptotic distribution, its cdf is already present somewhere in R and I would like to know how to access it. The R function ks.test contains the instruction

PVAL <- 1 - if (alternative == "two.sided") 
                .Call(C_pKolmogorov2x, STATISTIC, n)

but my own call to C_pKolmogorov2x does not work.


Solution

  • Relevant excerpt from the "Writing R extensions" manual

    Then, the directive in the NAMESPACE file

    useDynLib(myDLL, .registration = TRUE)

    causes the DLL to be loaded and also for the R variables foo, bar_sym, R_call_sym and R_version_sym to be defined in the package’s namespace.

    Translated to human speak this means (roughly) that the default place for all the non-R code is in the package namespace. Hence the need of triple colon.

    So if you find in the code the .Call(something,args), you can invoke it from the comandline by .Call(package:::something,args). This is why simple call to C_pKolmogorovx did not work. The R was not finding it, since package namespace is intended for the package, not the user.

    If you want to find out where the external code lies you need to look into 2 files. First NAMESPACE of the package to see whether the useDynLib is used to register the external code functions, and then look into src/init.c file where all the available external code functions from the package are registered.