Skip to content

how to do regression analysis for multiple dependent variables at once

3 messages · Hiroto Miyoshi, Jonathan Baron, Thomas Lumley

#
Dear R-users

I have, say, 5 dependent variables, d1 to d5.
And I also have 2 independent variable x1, x2.
Suppose I need to do regression analyses for all
the dependent variables, using the same set 
of independent variables, x1 and x2.

How can I do the analyses without writing five lines of
lm(d1~x1*x2)
lm(d2~x1*x2)
lm(d3~x1*x2)
lm(d4~x1*x2)
lm(d5~x1*x2)

I like to write the R codes something like
l <- c("d1","d2","d3","d4","d5")
for( i in l ) lm(i~x1*x2).

However, this does not work.

I hope you get the idea about what I want to do.
So, Could you help me.
Sincerely

---------------------------
Hiroto Miyoshi???????
h_m_ at po.harenet.ne.jp
#
On 02/15/03 14:08, Hiroto Miyoshi wrote:
lm(cbind(d1,d2,d3,d4,d5)~x1*x2)

This is because the dependent variable in lm() can be a matrix
instead of a vector.

It says this in "In introduction to R" under "Formula for
statistical models."  But I could not find this in the help page
for lm() or formula().
#
On Sat, 15 Feb 2003, Jonathan Baron wrote:
There's an allusion to it in describing the value returned by lm(), but
I'll add an actual description.

	-thomas