More Related Content
More from Yoonwhan Lee (20)
단순선형회귀분석예제
- 2. • 다음은 책의 페이지 수와 가격의 자료이다.
Pages Prices Pages Prices
637 27 496 20
336 15 673 25
336 14 562 24
430 15 229 10
164 9.5 316 13
533 20 217 8
529 22 296 12
509 20 115 7
419 16 257 11
596 24 649 22
- 3. 자료 가져오기
> bnp <- read.csv("bookNprice.csv", header=T)
> bnp
Pages Prices
1 637 27.0
2 336 15.0
3 336 14.0
…
18 115 7.0
19 257 11.0
20 649 22.0
> attach(bnp)
- 5. 회귀계수의 추정 - 최소제곱법
> lms <- lm(Prices ~ Pages)
> lms
Call:
lm(formula = Prices ~ Pages)
Coefficients:
(Intercept) Pages
2.19108 0.03503
절편 기울기
ß0 ß1
- 8. 회귀의 분산분석
회귀(모형)
> summary(aov(lms))
Df Sum Sq Mean Sq F value Pr(>F)
Pages 1 681.78 681.78 332.09 4.769e-13 ***
Residuals 18 36.95 2.05
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘
오차
- 10. > summary(lms)
Call:
lm(formula = Prices ~ Pages)
Residuals:
Min 1Q Median 3Q Max
-2.9228 -0.7875 -0.1059 0.9603 2.4975
절편
Coefficients: ß0
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.191079 0.859491 2.549 0.0201 *
Pages 0.035026 0.001922 18.223 4.77e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 기울기
0.05 ‘.’ 0.1 ‘ ’ 1 ß1
Residual standard error: 1.433 on 18 degrees of freedom
Multiple R-squared: 0.9486, Adjusted R-squared: 0.9457
F-statistic: 332.1 on 1 and 18 DF, p-value: 4.769e-13
- 12. • 적합값 : fitted
> fitted(lms)
1 2 3 4 5 6 7
24.502460 13.959720 13.959720 17.252137 7.935296 20.859786 20.719683
8 9 10 11 12 13 14
20.019169 16.866854 23.066406 19.563834 25.763386 21.875532 10.211968
15 16 17 18 19 20
13.259205 9.791659 12.558691 6.219036 11.192688 24.922769
• 잔차 : resid
> resid(lms)
1 2 3 4 5 6
2.49753964 1.04028032 0.04028032 -2.25213703 1.56470357 -0.85978584
7 8 9 10 11 12
1.28031703 -0.01916864 -0.86685415 0.93359402 0.43616567 -0.76338616
13 14 15 16 17 18
2.12446838 -0.21196800 -0.25920535 -1.79165941 -0.55869101 0.78096368
19 20
-0.19268807 -2.92276896