Thank you Paul, Barry and Patrick.

I will do what you recommand (the profiling).

I have heard several times that for example Matlab would be faster than R...
This is why I thought of switching to Python, though it is also interpreted.
I thought it would be faster.

Best,
Jean

2009/11/21 Patrick Burns <pbu...@pburns.seanet.com>

> One little thing that I think Barry
> meant to say.
>
> If the bottleneck is in your code, you
> may be able to improve the situation
> enough by merely rewriting the R code
> of your function.  If that doesn't work,
> then you can move to C.
>
>
>
> Patrick Burns
> patr...@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of "The R Inferno" and "A Guide for the Unwilling S User")
>
> Barry Rowlingson wrote:
>
>>  On Sat, Nov 21, 2009 at 2:29 PM, Jean Legeande <jean.legea...@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-...@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
>>
>> ______________________________________________
>> R-help@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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to