【问题标题】:invalid model formula in ExtractVars in R for no reasonR中ExtractVars中的无效模型公式无缘无故
【发布时间】:2020-12-15 17:34:32
【问题描述】:

我正在尝试构建一个简单的线性模型。有源表变量data_star

            x_st      y_st
    1   7.202602 4.0315130
    2   7.405203 2.4836105
    ...
    52 17.535288 7.2934321
    53 17.737890 3.7034159

看起来很简单,但 rstudio 这么说

model_new_star = lm('y_st~10.26909+x_st', data = data_star)

ExtractVars 中的模型公式无效。我错过了什么?

更有趣的是

model_star = lm("y_st~x_st", data = data_star)

效果很好

【问题讨论】:

  • 嗨toxicarchont,欢迎来到StackOverflow!您不能以这种方式在公式中定义固定常数。我认为以下内容可以回答您的问题:stackoverflow.com/questions/7333203/…
  • 你好,谢谢你,显然我只需要一个 I() over number+x_st,你链接到的问题有帮助!

标签: r


【解决方案1】:

在 10.26909+x_st 上添加一个 I(),使公式看起来像

model_new_star = lm(y_st~I(10.26909+x_st))

这是因为 R 对公式中算术运算符的解释不同

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 2017-04-11
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多