【问题标题】:syntax question in R model specificationR模型规范中的语法问题
【发布时间】:2011-10-02 05:43:01
【问题描述】:

查看 plyr 教程,我发现以下内容 准备:

b2 <- ddply(baseball, "id", transform, cyear = year - min(year) + 1)  
b2 <- ddply(b2, "id", transform, career = (cyear - 1) / max(cyear)) 
bruth <- subset(b2, id == "ruthba01")
# Could we model that as two straight lines?
bruth$p <- (bruth$career - 0.5) * 100

现在是一些模型

mod <- lm(g ~ p + p:I(p > 0), data = bruth)

和有什么区别?

mod <- lm(g ~ p + I(p > 0), data = bruth)

当我检查时

mod$model

在这两种情况下,它都会产生具有相同数字的相同列。
然而回归系数完全不同......

你知道这个符号是什么意思吗?

【问题讨论】:

  • 检查model.matrix(mod) 两种型号,您会发现不同之处。
  • 好把戏。非常感谢
  • @nicolas 或 @Ramnath 可以继续发布答案(不同的参数化)作为真正的答案......我最近在 r-sig-mixed-models 列表上发布了类似的回复:@987654321 @

标签: r model regression plyr


【解决方案1】:

运行以下代码查看不同模型的影响:

 with(bruth, plot(p, predict(mod), type="l" )  )
 with(bruth, points(p, g,  col="red") )
 with(bruth, lines(p, predict(mod2), lty=3, lwd=2, col="red") )
 title(main="Different uses of I() and interaction")

它强调了(任意?)连接点的选择对分段回归输出的影响。

【讨论】:

    猜你喜欢
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多