如何写出多变量响应的R公式?

时间:2022-05-05 13:30:31

In R I want to do some regression on multivariate response on all predictors, for univariate response, I know the formula is like

在R中我想对所有预测因子的多变量响应进行一些回归,对于单变量响应,我知道公式就像

y~., this is to use all predictors to regress y, what if now I face 100 response, I can not type 100 yi like y1+y2+y3...+y4~x, so how to use all predictors to regress multivariate response?

y~。,这是使用所有预测变量来回归y,如果现在我面对100响应,我不能像y1 + y2 + y3 ... + y4~x那样输入100 yi,那么如何使用所有预测变量来回归多变量反应?

2 个解决方案

#1


10  

In R, the multivariate formula is to use cbind() for your Y variable. Thus, the formula would be:

在R中,多变量公式是使用cbind()作为Y变量。因此,公式将是:

model <- lm(cbind(y1, y2, y3, y4)~x)

#2


1  

That's relatively easy if y is a matrix with 100 columns. In that case you do it the same way. For example:

如果y是具有100列的矩阵,则相对容易。在这种情况下,你以同样的方式做到这一点。例如:

lm(y ~ x)

will do a linear regression of y onto the columns of x.

将对y的列进行线性回归。

#1


10  

In R, the multivariate formula is to use cbind() for your Y variable. Thus, the formula would be:

在R中,多变量公式是使用cbind()作为Y变量。因此,公式将是:

model <- lm(cbind(y1, y2, y3, y4)~x)

#2


1  

That's relatively easy if y is a matrix with 100 columns. In that case you do it the same way. For example:

如果y是具有100列的矩阵,则相对容易。在这种情况下,你以同样的方式做到这一点。例如:

lm(y ~ x)

will do a linear regression of y onto the columns of x.

将对y的列进行线性回归。