[R] Help on making code faster-would C help ?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jul 20 17:05:43 CEST 2006


Without details it is hard to say, but if you do the WLS via lm.wfit, 
probably not.  If you are using lm() and taking the overhead 10000 times, 
that is the first thing to avoid.

As an example of this sort of thing, look at the C code for lqs{MASS} 
which does thousands of regressions quite quickly.

On Thu, 20 Jul 2006, Benn Fine wrote:

> Using R on windows....
> 
> I have the following code 
> 
> for(i in 1:10000) {
> 
> draw some random weights
> 
> perfom a weighted least squares regression
> 
> some simple addition and multiplication
> }
> 
> The code works fine but is slow. 
> 
> I have mingw installed and can dyn.load, although I am
> more used to doing this on Unix than Windows.
> 
> Would it make sense to re-write the whole thing in
> C ? I am vectorizing the random draws-the speed
> culprit is looping and the matrix manipulations.
> 
> My guess is to use the matrix routines from gls-does
> this sound feasible ?
> 
> Thanks!
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list