liner regression

2018/07/04

간단한 linear regression에 대한 R 코드.

참고자료

x <- c(30, 20, 60, 80, 40, 50, 60, 30, 70, 60)
y <- c(73, 50, 128, 170, 87, 108, 135, 69, 148, 132)

plot(x, y)

beginr::plotlm(x, y)

## [[1]]
##             Estimate Std. Error   t value     Pr(>|t|)
## (Intercept)       10 2.50293945  3.995302 3.975760e-03
## x                  2 0.04696682 42.583252 1.019588e-10
## 
## [[2]]
## [1] 0.9956076
r8.lm <- lm(y ~ x)
summary(r8.lm)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##   -3.0   -2.0   -0.5    1.5    5.0 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 10.00000    2.50294   3.995  0.00398 ** 
## x            2.00000    0.04697  42.583 1.02e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.739 on 8 degrees of freedom
## Multiple R-squared:  0.9956, Adjusted R-squared:  0.9951 
## F-statistic:  1813 on 1 and 8 DF,  p-value: 1.02e-10
confint(r8.lm)
##                2.5 %    97.5 %
## (Intercept) 4.228211 15.771789
## x           1.891694  2.108306
plot(ellipse::ellipse(r8.lm), type="l")