[R] Python and R
Esmail Bonakdarian
esmail.js at gmail.com
Thu Feb 19 14:30:05 CET 2009
Hi Kenn,
Thanks for the suggestions, I'll have to see if I can figure out how to
convert the relatively simple call to lm with an equation and the data file
to the functions you mention (or if that's even feasible).
Not an expert in statistics myself, I am mostly concentrating on the
programming aspects of R. Problem is that I suspect my colleagues who
are providing some guidance with the stats end are not quite experts
themselves, and certainly new to R.
Cheers,
Esmail
Kenn Konstabel wrote:
> 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
More information about the R-help
mailing list