2009-11-26 53 views
4

我想知道是否有一種方法可以包括用於線性迴歸模型等包括線性迴歸模型,其中R

R = LM(Y〜X1 + X2)誤差項誤差項?

+5

你是什麼錯誤意味着什麼?您的代碼將符合以下線性模型: y = a + b1 * x1 + b2 * x2 + e 其中e是錯誤。 –

+1

所以模型已經包含錯誤條款? 但我已經看到這個: y〜A * B +錯誤(C) – phpdash

回答

4

代碼r = lm(y ~ x1+x2)表示我們將y建模爲x1和x2的線性函數。由於該模型不完美,因此會存在剩餘期限(即模型未能適應的剩餘期限)。

在數學,如羅布海德門中的註釋y = a + b1*x1 + b2*x2 + e,其中ab1b2是常數,e是您的殘差(其被假定爲正態分佈)指出。

看一個具體的例子,可以考慮隨R.虹膜數據

model1 <- lm(Sepal.Length ~ Sepal.Width + Petal.Length + Petal.Width, data=iris) 

現在,我們可以提取模型中的常數(相當於ab1b2在這種情況下b3太)。

> coefficients(model1) 
(Intercept) Sepal.Width Petal.Length Petal.Width 
1.8559975 0.6508372 0.7091320 -0.5564827 

已經爲模型中使用的每一行數據計算了殘差。

> residuals(model1) 
      1    2    3    4    5  
0.0845842387 0.2100028184 -0.0492514176 -0.2259940935 -0.0804994772 
# etc. There are 150 residuals and 150 rows in the iris dataset. 

(編輯:剪切彙總信息不相應和。)


編輯:

Error價值,你在你的意見提在幫助頁面AOV的解釋。

If the formula contains a single ‘Error’ term, this is used to 
specify error strata, and appropriate models are fitted within 
each error stratum. 

比較以下(改編自?aov頁。)

> utils::data(npk, package="MASS") 
> aov(yield ~ N*P*K, npk) 
Call: 
    aov(formula = yield ~ N * P * K, data = npk) 

Terms: 
         N  P  K  N:P  N:K  P:K N:P:K Residuals 
Sum of Squares 189.2817 8.4017 95.2017 21.2817 33.1350 0.4817 37.0017 491.5800 
Deg. of Freedom  1  1  1  1  1  1  1  16 

Residual standard error: 5.542901 
Estimated effects may be unbalanced 

> aov(yield ~ N*P*K + Error(block), npk) 
Call: 
aov(formula = yield ~ N * P * K + Error(block), data = npk) 

Grand Mean: 54.875 

Stratum 1: block 

Terms: 
        N:P:K Residuals 
Sum of Squares 37.00167 306.29333 
Deg. of Freedom   1   4 

Residual standard error: 8.750619 
Estimated effects are balanced 

Stratum 2: Within 

Terms: 
         N   P   K  N:P  N:K  P:K Residuals 
Sum of Squares 189.28167 8.40167 95.20167 21.28167 33.13500 0.48167 185.28667 
Deg. of Freedom   1   1   1   1   1   1  12 

Residual standard error: 3.929447 
1 out of 7 effects not estimable 
Estimated effects may be unbalanced 
+1

嘿裏奇,這看起來很有趣。所以我想我可以在R中嘗試這個: > v = aov(yield_N * P * K,npk) > v2 = aov(yield_N * P * K + Error(block),npk)係數(v) >係數(v2) 這是什麼類型的迴歸?什麼是係數,如N1:P1和N1:P1:K1? – phpdash

+0

@phpdash:這有時被稱爲分裂圖ANOVA。邁克爾克勞利在統計計算中有一個循序漸進的例子。 http://books.google.com/books?id=OlPUa6lVeb0C&pg=PA345# –