[R] Memory Allocation in R and S-Plus: And functions from R to S-Plus

Thomas Lumley tlumley at u.washington.edu
Tue Jan 8 23:33:29 CET 2002


On Tue, 8 Jan 2002, kkelley wrote:

> Hello Everyone,
>
> I've been told that the memory allocation in R and S-Plus is different, with R
> being better at doing simulations for whatever reason(s).  I was wondering if
> anyone could enlighten me on the differences in the memory usage/allocation
> (preferably in layman's terms!).

It's not true that R is universally better, though there certainly exist
real examples where it is much better (and others where it's worse)

> The reason I ask this is because of a simulation I am trying to run.  In it, I
> need to use the pt( ) function with a noncentrality argument.  The pt( )
> function in S-Plus does not allow for a noncentral parameter, so I need to use
> R.  This is fine, but for some reason, R is taking a huge amount of time, but
> doing the same thing in S-Plus (without the noncentral parameter in pt( ))
> does not take much time at all.   So, my main question is why does R take so
> much longer?  One problem may be because there are three
> "for" loops in the program, but still S-Plus does it quickly (with the caveat
> of no noncentral parameter).

There's no necessary reason why three for() loops should be a problem,
though if you could vectorise one or more of them it should help. The
problem may well be the noncentrality parameter. The noncentral
distribution is slower to compute, especially for large quantiles and
large noncentrality.

You could see if removing the noncentrality parameter makes much
difference to the speed.  For a more thorough answer you can use the
profiler (see help(Rprof)) to find out where your program is spending its
time.

> I was also wondering how to get a function from R into S-Plus, specifically
> the pt( ) function.

The mathematical functions in R can be compiled as a separate dynamic
library, which you might be able to load into S-Plus. You could then
use .C() to call the C pnt function. This email list is not the best place
to find out the details of how to do it. :)


	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list