Dear R users, I would like to make my R code for MCMC faster. It is possible to integrate C code into R but I think C is too complicated for me. I would need a C introduction only for MCMC and I do not know if such a thing exists. I was thinking of Python (and scipy). Where could I read about its integration into R ? How developed are the statistical packages in Python ? I could not find a Python package on the web with functions to simulate Wishart, or multivariate gamma or student distributions. Since I am a little bit lost, I write this message to the R help list. Sorry for these naive questions and thanks for your help. Best, Jean [[alternative HTML version deleted]]
Hi Jean, You can integrate R and Python using RSPython or Rpy. But why would Python be faster than R? Both are interpreted languages and probably about as fast (please someone correct me if I'm wrong). It probably only help if there is a C mcmc implementation linked to python (that you link to R). Isn't there an mcmc package for R that uses a fast implementation of mcmc? See also the Bayesian taskview [1]. cheers, Paul [1] http://cran.r-project.org/web/views/Bayesian.html Jean Legeande schreef:> Dear R users, > > I would like to make my R code for MCMC faster. It is possible to integrate > C code into R but I think C is too complicated for me. I would need a C > introduction only for MCMC and I do not know if such a thing exists. > > I was thinking of Python (and scipy). Where could I read about its > integration into R ? How developed are the statistical packages in Python ? > I could not find a Python package on the web with functions to simulate > Wishart, or multivariate gamma or student distributions. > > Since I am a little bit lost, I write this message to the R help list. Sorry > for these naive questions and thanks for your help. > > Best, > Jean > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On Sat, Nov 21, 2009 at 2:29 PM, Jean Legeande <jean.legeande at gmail.com> wrote:> Dear R users, > > I would like to make my R code for MCMC faster. It is possible to integrate > C code into R but I think C is too complicated for me. I would need a C > introduction only for MCMC and I do not know if such a thing exists. > > I was thinking of Python (and scipy). Where could I read about its > integration into R ? How developed are the statistical packages in Python ? > I could not find a Python package on the web with functions to simulate > Wishart, or multivariate gamma or student distributions. > > Since I am a little bit lost, I write this message to the R help list. Sorry > for these naive questions and thanks for your help. >Have you done a profile of your MCMC code to see where the bottleneck is? Without doing that first any effort could be a total waste of time. R can do a lot of it's calculations at the same level as C, so if 80% of your time is spent inverting matrices then converting to Python or C (or even assembly language) isn't going to help much since R's matrix inversion is done using C code (and quite possibly very optimised C code with maybe some assembly language too). So do a profile (see ?Rprof) and work out the bottleneck. It might be one of your functions, in which case just re-writing that in C and linking to R (see programmers guide and a good C book) will do the job. My hunch is that Python and R run at about the same speed, and both use C libraries for speedups (Python primarily via the numpy package). You can call the GSL from Python, and there are probably tricks for getting the distributions you want: http://www.mailinglistarchive.com/help-gsl at gnu.org/msg00096.html describes how to get samples from a Wishart. However using the GSL from Python probably wont be much faster than using R because again it's all at the C level already. Did I suggest you profile your code? Barry
There is work going on on two byte compilers for R: http://www.stat.uiowa.edu/~luke/R/compiler/ http://www.milbo.users.sonic.net/ra You could check whether running under either of those speeds up your R code sufficiently that you don't need to rewrite it. On Sat, Nov 21, 2009 at 9:29 AM, Jean Legeande <jean.legeande at gmail.com> wrote:> Dear R users, > > I would like to make my R code for MCMC faster. It is possible to integrate > C code into R but I think C is too complicated for me. I would need a C > introduction only for MCMC and I do not know if such a thing exists. > > I was thinking of Python (and scipy). Where could I read about its > integration into R ? How developed are the statistical packages in Python ? > I could not find a Python package on the web with functions to simulate > Wishart, or multivariate gamma or student distributions. > > Since I am a little bit lost, I write this message to the R help list. Sorry > for these naive questions and thanks for your help. > > Best, > Jean > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >