'다중회귀분석'에 해당되는 글 1건
- 2019.02.17 :: 다중선형분석 example 2
> x <- c(1,2,3,4,5,6,7,8,9)
> y <- c(5,3,2,3,4,6,10,12,18)
> df1 <- data.frame(x,y)
> plot(df1)
> x2 <- x^2
> m <- lm(y~x, data=df1)
> m
Call:
lm(formula = y ~ x, data = df1)
Coefficients:
(Intercept) x
-1.167 1.633
> summary(m)
Call:
lm(formula = y ~ x, data = df1)
Residuals:
Min 1Q Median 3Q Max
-3.0000 -2.3667 -0.2667 0.9000 4.5333
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.1667 2.2296 -0.523 0.61694
x 1.6333 0.3962 4.122 0.00445 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.069 on 7 degrees of freedom
Multiple R-squared: 0.7083, Adjusted R-squared: 0.6666
F-statistic: 16.99 on 1 and 7 DF, p-value: 0.004446
>
> df2 <- cbind(x2,df1)
> lm(y~x+x2,data=df2)
Call:
lm(formula = y ~ x + x2, data = df2)
Coefficients:
(Intercept) x x2
7.1667 -2.9121 0.4545
> summary(lm(y~x+x2,data=df2))
Call:
lm(formula = y ~ x + x2, data = df2)
Residuals:
Min 1Q Median 3Q Max
-0.9606 -0.1606 0.0303 0.2242 0.9455
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.16667 0.78728 9.103 9.87e-05 ***
x -2.91212 0.36149 -8.056 0.000196 ***
x2 0.45455 0.03526 12.893 1.34e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6187 on 6 degrees of freedom
Multiple R-squared: 0.9898, Adjusted R-squared: 0.9864
F-statistic: 292.2 on 2 and 6 DF, p-value: 1.05e-06
'R' 카테고리의 다른 글
다변량분석 - 상관분석 (0) | 2019.02.18 |
---|---|
step 함수를 이용한 전진선택법 적용 example (0) | 2019.02.17 |
다중선형회귀 example (0) | 2019.02.17 |
단순회귀분석 (0) | 2019.02.12 |
이상값 검색 (0) | 2019.02.10 |