【发布时间】:2020-09-24 02:47:20
【问题描述】:
首先,我会给你一些可重现的代码:
library(ggplot2)
y = c(0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 3, 0, 6, 2, 8, 16, 21, 39, 48, 113, 92, 93 ,127, 159, 137, 46, 238, 132 ,124, 185 ,171, 250, 250 ,187, 119 ,151, 292, 94, 281, 146, 163 ,104, 156, 272, 273, 212, 210, 135, 187, 208, 310, 276 ,235, 246, 190, 232, 254, 446,
314, 402 ,276, 279, 386 ,402, 238, 581, 434, 159, 261, 356, 440, 498, 495, 462 ,306, 233, 396, 331, 418, 293 ,431 ,300, 222, 222, 479 ,501, 702
,790, 681)
x = 1:length(y)
现在,我正在尝试为此数据集构建 3 次多项式回归曲线。我想知道这个模型的系数,summary(lm(formula=y~poly(x,3)))。我得到了一个荒谬的结果。
Call:
lm(formula = y ~ poly(x, 3))
Residuals:
Min 1Q Median 3Q Max
-253.696 -47.582 -9.709 44.314 271.183
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 223.978 9.703 23.083 <2e-16 ***
poly(x, 3)1 1420.644 91.538 15.520 <2e-16 ***
poly(x, 3)2 62.375 91.538 0.681 0.497
poly(x, 3)3 130.161 91.538 1.422 0.159
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 91.54 on 85 degrees of freedom
Multiple R-squared: 0.7411, Adjusted R-squared: 0.732
F-statistic: 81.12 on 3 and 85 DF, p-value: < 2.2e-16
这对我的模型来说太高了,我很困惑为什么会返回这个输出。
为什么会这样?我哪里错了?
【问题讨论】:
-
默认情况下
poly()创建正交多项式 - 这些不直接反映 x^1、x^2、x^3 并且有点难以解释。尝试lm(y ~ poly(x, 3, raw = TRUE)),您应该会看到更容易解释的结果。 -
您好,Marius,感谢您的帮助!如果您可以发布该评论作为答案,我可以关闭此问题并接受您的回答。
标签: r model regression polynomial-approximations