-1

I know about lm(y~. , data) but I'm wondering about the opposite direction

If I want to put multiple y to lm function, how should I do that? Using for? loop?

My desired result is getting each p-value and beta value of Y. There is just one X.

G5W
  • 36,531
  • 10
  • 47
  • 80
hwan
  • 21
  • 1
  • 3

1 Answers1

1

lm supports a matrix on the LHS of the formula:

f <- as.formula(sprintf("cbind(%s) ~ Species", 
                         paste(names(iris)[names(iris) != "Species"], collapse = ", ")))
#cbind(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) ~ Species
summary(lm(f, data = iris))
Roland
  • 127,288
  • 10
  • 191
  • 288