【问题标题】:lm() linear model - attributeslm() 线性模型 - 属性
【发布时间】:2012-09-13 19:37:18
【问题描述】:

所以我对 lm() 命令感到有些困惑。我用lm(x~y, mydata)lm(y~x, mydata) 试了一下,得到了不同的输出。 那么这只是将哪个变量用作 x 以及将哪个变量用作 y 吗?很抱歉提出这样一个菜鸟问题,但我不确定,也找不到任何解释该命令参数的内容!

【问题讨论】:

  • 你说得对,它们是不同的。选择在y (x~y) 上建模x 还是在x (y~x) 上建模y 是一个统计问题,而不是编程问题。你的数据是什么?
  • 当您不知道如何在 R 中使用某个函数时,请使用? 获取有关该函数的帮助。例如?lm 显示lm 帮助页面。其他有用的命令是??,它在帮助中查找一个术语(例如??regression)和RSiteSearch("something")

标签: r lm


【解决方案1】:

可以在函数的帮助页面上找到答案。在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

【讨论】:

  • 太棒了!谢谢大家!不知道如何在 R 中获得特定命令的帮助!这也很有帮助!
  • @cups - 另请查看 rseek.org 以获取另一个好资源。 R 当然有一个陡峭的初始学习曲线,但你会很快学会的!
猜你喜欢
  • 2017-02-19
  • 1970-01-01
  • 2012-08-18
  • 2019-10-25
  • 2013-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多