Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 为什么lm函数给出的结果高得离谱?_R_Model_Regression_Polynomial Approximations - Fatal编程技术网

R 为什么lm函数给出的结果高得离谱?

R 为什么lm函数给出的结果高得离谱?,r,model,regression,polynomial-approximations,R,Model,Regression,Polynomial Approximations,首先,我将给您一些可复制的代码: 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, 1

首先,我将给您一些可复制的代码:

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)
现在,我正试图为这个数据集构造一条三次多项式回归曲线。我想知道这个模型的系数,通过
总结(lm(公式=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
呼叫:
lm(公式=y~多边形(x,3))
残差:
最小1季度中值3季度最大值
-253.696  -47.582   -9.709   44.314  271.183 
系数:
估计标准误差t值Pr(>t)

(截距)223.978 9.703 23.083我想你想要的是:

lm(y ~ poly(x, 3, raw = TRUE))

我希望这有帮助

默认情况下,
poly()
创建正交多项式-这些多项式不直接反映x^1、x^2、x^3,并且有点难以解释。试试
lm(y~poly(x,3,raw=TRUE))
你会看到更容易解释的结果。嗨,马吕斯,谢谢你的帮助!如果你能把这句话作为回答,我可以结束这个问题,接受你的回答。