非常奇怪,下边一个例子excel进行的回归和R进行的回归得到的决定系数R^2居然不一样!
slope SME
0.008091681 0.010573409
0.01400749 0.023963562
0.021630862 0.046281063
0.020913772 0.045595532
0.010371885 0.011485726
0.011579039 0.020312769
0.002106411 0.001840598
0.009887661 0.021263929
其中第一列是自变量,第二列是依变量,现在在R中,输入命令
nisM<-lm(SME~slope-1) #不需要intercept
得到:
> summary(nisM)
Call:
lm(formula = MSE ~ slope - 1)
Residuals:
Min 1Q Median 3Q Max
-0.008728 -0.003800 -0.002259 0.002527 0.004838
Coefficients:
Estimate Std. Error t value Pr(>|t|)
slope 1.9489 0.1264 15.42 1.16e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.004912 on 7 degrees of freedom
Multiple R-squared:
0.9714, Adjusted R-squared: 0.9673
F-statistic: 237.8 on 1 and 7 DF, p-value: 1.163e-06
但是excel进行相应的回归得到的是0.906
我又在R中编写了:
> a<-coefficients(nisM)[1]
> 1-sum((MSE-a*slope)^2)/sum((MSE-mean(MSE))^2)
得到了
[1] 0.90604
居然和excel得到的结果一致,但是为什么R中的结果(0.9714
本文来自: 人大经济论坛 详细出处参考:
http://www.pinggu.org/bbs/viewth ... amp;from^^uid=1658203)不一样呢?