Skip to content
Prev 280900 / 398503 Next

Other ways to lm() regression? (non-loop?)

Hello, iliketurtles (?),

for whatever strange reasons you want to regress all y-columns on all 
x-columns, maybe

reg <- apply( x, 2, function( xx) lm( y ~ xx))
do.call( "cbind", lapply( reg, coef))

does what you want. (To understand what the code above does, check the 
documentation for lm(): "If response is a matrix a linear model is fitted 
separately by least-squares to each column of the matrix.")

Hth  --  Gerrit
On Mon, 26 Dec 2011, iliketurtles wrote: