**W**hile 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

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

which means that the Kolmogorov distribution is coded as a C function C_pKolmogorov2x in R. However, I could not call the function myself.

> .Call(C_pKolmogorov2x,.3,4) Error: object 'C_pKolmogorov2x' not found

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

> .Call(stats:::C_pKolmogorov2x,STAT=.3,n=4) [1] 0.2292

## what’s wrong with package comment?!

Posted in Books, R, Statistics, University life with tags comment package, Introducing Monte Carlo Methods with R, LaTeX, R, verbatim on May 4, 2012 by xi'anIspent most of the Sunday afternoon trying to understand why definingdid not have the same effect as writing the line

until I found there is a clash due to the

commentpackage… The assuredly simple codeproduces an error message:

This is quite an inconvenience as I need to compile my solution manual for “” with the even-numbered exercises commented out or not depending on the version… (Leaving this package out and using the comment command within theIntroducing Monte Carlo Methods with Rverbatimpackage does not work either becauseeradoes not seem to be recognised as the end of a commented part…)## Share:

5 Comments »