2013-10-17 17 views
0

我給出以下數據:顯着的二次項 - 線性迴歸 - R的

enter image description here

有人告訴我先適應二次模型。

enter image description here

> time = c(10,20,15,11,11,19,11,13,17,18,16,16,17,18,10) 
> experience = c(24,1,10,15,17,3,20,9,3,1,7,9,7,5,20) 
> fit = lm (time ~ experience + I(experience^2)) 
> summary(fit) 

Call: 
lm(formula = y ~ x + I(x^2)) 

Residuals: 
    Min  1Q Median  3Q  Max 
-1.8287 -0.8300 0.5054 0.7476 1.1713 

Coefficients: 
      Estimate Std. Error t value Pr(>|t|)  
(Intercept) 20.091108 0.724705 27.723 3e-12 *** 
x   -0.670522 0.154706 -4.334 0.000972 *** 
I(x^2)  0.009535 0.006326 1.507 0.157605  
--- 
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 1.091 on 12 degrees of freedom 
Multiple R-squared: 0.9162, Adjusted R-squared: 0.9022 
F-statistic: 65.59 on 2 and 12 DF, p-value: 3.465e-07 

一切似乎罰款在那裏。

我的模型是

y = 20.091-.671x+.0095x^2 

繪製它:

> x = seq(0,25, by = .1) 
> y = fit$coefficient[1]+fit$coefficient[2]*x+fit$coefficient[3]*x^2 
> lines(x,y) 

enter image description here

再次,一切似乎都很好。

但後來我被告知測試二次項在a = .1顯着性水平上是否顯着。

所以我做

> fit1 = lm (time ~ experience + I(experience^2)) 
> fit2 = lm(time~experience) 
> anova(fit2, fit1) 

Analysis of Variance Table 

Model 1: time ~ experience 
Model 2: time ~ experience + I(experience^2) 
    Res.Df RSS Df Sum of Sq  F Pr(>F) 
1  13 16.984       
2  12 14.280 1 2.7037 2.2719 0.1576 

所以對於二次項我的F值是2.27。對應於.1576的概率。因此,二次項在a = 0.112時顯着,但我的教授指出我們應該找到二次項對於我們的模型來說是微不足道的。我在這裏做錯了什麼?

+2

這應該被移到stats.stackexchange.com。和你的教授是正確的 –

+2

「重要」的意思是**小於**阿爾法。所以你的結果是微不足道的,就像你的教授指出的那樣。 – gung

+0

那麼值.1576究竟是什麼意思?用普通英語 – user2079802

回答

1

你無法做的是構造正交多項式項。 R中的poly()函數是爲此目的而設計的。

time = c(10,20,15,11,11,19,11,13,17,18,16,16,17,18,10) 
experience = c(24,1,10,15,17,3,20,9,3,1,7,9,7,5,20) 
fit = lm (time ~ poly(experience, degree=2)) 
summary(fit) 
#-------------- 
Call: 
lm(formula = time ~ poly(experience, degree = 2)) 

Residuals: 
    Min  1Q Median  3Q  Max 
-1.8287 -0.8300 0.5054 0.7476 1.1713 

Coefficients: 
           Estimate Std. Error t value Pr(>|t|)  
(Intercept)     14.8000  0.2817 52.544 1.48e-15 *** 
poly(experience, degree = 2)1 -12.3861  1.0909 -11.354 8.94e-08 *** 
poly(experience, degree = 2)2 1.6443  1.0909 1.507 0.158  
--- 
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 1.091 on 12 degrees of freedom 
Multiple R-squared: 0.9162, Adjusted R-squared: 0.9022 
F-statistic: 65.59 on 2 and 12 DF, p-value: 3.465e-07 

您的F統計量不是特定於二次項,而是真正將零模型與兩個項模型進行比較。

+0

使用poly(x,2),您將如何測試x和x^2與Lrts的顯着性,而不用測試null模型與兩個條款的模型? – user1320502

+0

你需要用更精確的語言解釋你的意思是「用Lrts測試x和x^2的意義」。你有F檢驗,這是一個LR檢驗,你有兩個是Wald檢驗的t檢驗。對於度數= 2的Wald檢驗應該與anova比較這個模型與x爲協變量的一度(非多)模型。 –