For a neuroimaging application, I'm trying to fit many linear models by least squares in R (standard call to
From the help page for
If ‘response’ is a matrix a linear model is fitted separately by least-squares to each column of the matrix.
So it would seem that a simple approach would be to combine all the different y vectors into a matrix and pass that as the response in a single call to
lm. For example:
(fit <- lm( cbind(Sepal.Width,Sepal.Length) ~ Petal.Width+Petal.Length+Species, data=iris)) summary(fit) summary(fit) coef(summary(fit)) coef(summary(fit)) sapply( summary(fit), function(x) x$r.squared )