lm does lots of computations, some of which you may never need. If speed
really matters, you might want to compute only those things you will really
use. If you only need coefficients, then using %*%, solve and crossprod will
be remarkably faster than lm

# repeating someone else's example
# lm(DAX~., EuStockMarkets)

 y <- EuStockMarkets[,"DAX"]
 x <- EuStockMarkets
 x[,1]<-1
colnames(x)[1] <- "Intercept"

lm(y ~ x-1)
solve(crossprod(x), t(x))%*%y    # probably this can be done more
efficiently

# and a naive timing

> system.time( for(i in 1:1000) lm(y ~ x-1))
   user  system elapsed
  14.64    0.33   32.69
> system.time(for(i in 1:1000) solve(crossprod(x), crossprod(x,y)) )
   user  system elapsed
   0.36    0.00    0.36


Also lsfit() is a bit quicker than lm or lm.fit.

Regards,
Kenn



On Wed, Feb 18, 2009 at 2:33 PM, Esmail Bonakdarian <esmail.js@gmail.com>wrote:

> Barry Rowlingson wrote:
>
>>
>>
>>  - and the bulk of the time in the regression calls will be taken up
>> by C code in the underlying linear algebra libraries (lapack, blas,
>> atlas and friends).
>>
>
> ah, good point.
>
>   Your best bet for optimisation in this case would be making sure you
>> have the best libraries for your architecture. That's a bit beyond me
>> at the moment, others here can probably tell you about getting the
>> best performing library for your system.
>>
>>  This can also speed up Python (scipy or numpy) code that uses the
>> same libraries.
>>
>
> thanks for the suggestions Barry, I mostly run on intel machines, but
> using two flavors of Linux and also Windows XP - I grab any machine I can
> to
> help run this. R versions range from 2.6.x (Fedora) to 2.8.1 (XP) at the
> moment.
>
> Another post suggested I look at lm.fit in place of lm to help speed things
> up, so I'm going to look at that next.
>
> Appreciate all the helpful posts here.
>
> Esmail
>
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]


