lm()线性模型 - 属性

lis*_*isa 1 r lm

所以我对lm() - 命令感到有些困惑.我试了一下lm(x~y, mydata),并lm(y~x, mydata)和我有不同的输出.那么,哪个变量用作x,哪个变量用作y?我很抱歉问这样一个noob问题,但我不确定,我找不到任何解释该命令参数的东西!

Cha*_*ase 8

答案可以在该功能的帮助页面上找到.在Details我们的部分中:

A typical model has the form response ~ terms where response is the (numeric) response vector and terms is a series of terms which specifies a linear predictor for response.

还有更多细节(也从lm帮助页面链接到formula.在详细信息部分中formula,我们有:

The ~ operator is basic in the formation of such models. An expression of the form y ~ model is interpreted as a specification that the response y is modelled by a linear predictor specified symbolically by model.

总而言之,您可以用符号术语定义模型,其中LHS是您的响应变量,RHS是您的预测变量.你会得到不同的答案,因为在一个模型中,y是你的响应变量而另一个是x.

如果您不知道,可以?在命令行中访问几乎所有功能的帮助页面,即?lm?formula.