Archive for C code

another R new trick [new for me!]

Posted in Books, Kids, R, Statistics, University life with tags , , , , , , , on July 16, 2014 by xi'an

La Defense, Dec. 10, 2010While 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

\max_x |\hat{F_n}(x)-F(x)|

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

CosmoPMC released

Posted in R, Statistics, University life with tags , , , , , , on January 13, 2011 by xi'an

Martin Kilbinger, an astronomer (cosmologist) with whom we had worked on population Monte Carlo for cosmological inference [during the ANR-05-BLAN-0283- 04 ANR ECOSSTAT grant], has made the PMC C codes available on the CosmoPMC webpage. He has also written a CosmoPMC manual that is now available from arXiv. And he very kindly associated me to this publication, even though I never directly contributed to the codes… On a wider perspective, this collaboration between cosmologists and Bayesian and computational statisticians was both fruitful and enjoyable and I hope we can pursue it in the future. A very nice thing about astronomers (among many!) is that they naturally adopt a Bayesian way of thinking about their parameters. This, plus their high math and programming skills, makes the cost of entering a collaboration very low!

%d bloggers like this: