[R] Row-by-row regression on matrix
murali.menon at uk.abnamro.com
murali.menon at uk.abnamro.com
Wed Sep 19 18:50:14 CEST 2007
Folks,
I have a 3000 x 4 matrix (y), which I need to regress row-by-row against a
4-vector (x) to create a
matrix lm.y of intercepts and slopes. To illustrate:
y <- matrix(rnorm(12000), ncol = 4)
x <- c(1/12, 3/12, 6/12, 1)
system.time(lm.y <- t(apply(y, 1, function(z) lm(z ~ x)$coefficient)))
[1] 44.72 18.00 69.52 NA NA
Takes more than a minute to do (and I need to do many similar regressions
a day).
Is there a more efficient way of handling this?
I'm running R 2.4.1 on Windows XP Service Pack 2 on a Intel Xeon dual-core
2.66GHz with 3GB RAM.
Thanks very much,
Murali
---------------------------------------------------------------------------
This message (including any attachments) is confidential and...{{dropped}}
More information about the R-help
mailing list