-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
  • 34,378
  • 10
  • 39
  • 71
hwan
  • 11
  • 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
  • 122,144
  • 10
  • 182
  • 276