# 데이터 구조 확인
#glimpse(mtcars)
#head(mtcars)
#tail(mtcars)
#summary(mtcars)
# lm 회귀분석 사용함수
model <- lm(mpg~hp, data = mtcars) # 독립변수 1개, 단순선형(직선) 회귀
summary(model)
##
## Call:
## lm(formula = mpg ~ hp, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.7121 -2.1122 -0.8854 1.5819 8.2360
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 30.09886 1.63392 18.421 < 2e-16 ***
## hp -0.06823 0.01012 -6.742 1.79e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.863 on 30 degrees of freedom
## Multiple R-squared: 0.6024, Adjusted R-squared: 0.5892
## F-statistic: 45.46 on 1 and 30 DF, p-value: 1.788e-07
##
## Call:
## lm(formula = mpg ~ hp, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.7121 -2.1122 -0.8854 1.5819 8.2360
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 30.09886 1.63392 18.421 < 2e-16 ***
## hp -0.06823 0.01012 -6.742 1.79e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.863 on 30 degrees of freedom
## Multiple R-squared: 0.6024, Adjusted R-squared: 0.5892
## F-statistic: 45.46 on 1 and 30 DF, p-value: 1.788e-07
# Residuals: 잔차(오차)
# coefficients: 회귀계수(Estimate)
# (Intercept): 절편(상수): 30.9886
# 독립변수 hp 회귀계수는: -0.06823
# pr(>|t|) 유의확률입니다.
# 0.000000179<유의수준 0.05
# 귀무가설: 회귀계수는 0이다.
# 대립가설: 회귀계수는 0이 아니다.
# 따라서 귀무가설 기각, 통계적으로 유의한 변수라고 합니다.
format(1.79e-07 , scientific=FALSE)
## [1] "0.000000179"
## [1] "0.000000179"