简体   繁体   English

lm()线性模型-属性

[英]lm() linear model - attributes

So I get a bit confused by the lm()-command. 所以我对lm()命令有些困惑。 I tried it with lm(x~y, mydata) and lm(y~x, mydata) and I got different output. 我尝试了lm(x~y, mydata)lm(y~x, mydata) ,得到了不同的输出。 So is that just which variable to use as x and which one to use as y? 那么,哪个变量用作x以及哪个变量用作y? I'm sorry to ask such a noob question but I am not sure and I coulnd't find anything explaining the parameters of that command! 很抱歉提出这样的菜鸟问题,但我不确定,我找不到任何能解释该命令参数的信息!

The answers can be found on the help page for the function. 答案可以在该功能的帮助页面上找到。 In the Details section we have: 在“ 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.

There are more details (also linked to from the lm help page to formula . In the details sections for formula , we have: 还有更多的细节(也与从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.

So to summarize, you define your model in symbolic terms where the LHS is your response variable, and the RHS are your predictor variable(s). 综上所述,您可以用符号术语定义模型,其中LHS是您的响应变量,而RHS是您的预测变量。 You get different answers because in one model, y is your response variable and the other is x . 您得到不同的答案,因为在一个模型中, y是您的响应变量,而另一个是x

If you weren't aware, you can access the help page for nearly all functions with ? 如果您不知道,可以使用?访问几乎所有功能的帮助页面? at the command line, ie ?lm or ?formula . 在命令行上,即?lm?formula

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM