는 R

2009-11-26 7 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의 선형 함수로 모델링한다는 것을 의미합니다. 모델이 완전하지 않기 때문에, 잔여 항 (즉, 모델이 적합하지 못한 좌상)이있을 것이다. 롭 Hyndman이 a, b1b2는 상수와 e이 (정규 분포하는 것으로 가정되는) 당신의 잔여 인 코멘트 y = a + b1*x1 + b2*x2 + e에서 언급 한 바와 같이

수학에서

.

a, b1, b2에 너무이 경우 b3

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

우리는 모델의 정수를 추출 할 수 있습니다 (해당 R.와 함께 제공되는 홍채 데이터를 고려, 구체적인 예를 살펴하려면).

> 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. 

(편집 :와 관계있는하지 컷 요약 정보.)


편집 :

당신이 AOV에 대한 도움말 페이지에 설명에 귀하의 의견에 언급 Error 값 .

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

안녕하세요, Richie,이게 재미있어 보여요. 그래서 나는 이것을 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라고도합니다. Michael Crawley의 통계 컴퓨팅에 대한 단계별 예제가 있습니다. http://books.google.com/books?id=OlPUa6lVeb0C&pg=PA345# –