# 문제1
rm(list=ls())
ls()
## character(0)
data(faithful)
head(faithful)
## eruptions waiting
## 1 3.600 79
## 2 1.800 54
## 3 3.333 74
## 4 2.283 62
## 5 4.533 85
## 6 2.883 55
model_1 <- lm(eruptions ~ waiting, data = faithful) #독립변수 1개 단순선형 회귀
summary(model_1)
##
## Call:
## lm(formula = eruptions ~ waiting, data = faithful)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.29917 -0.37689 0.03508 0.34909 1.19329
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.874016 0.160143 -11.70 <2e-16 ***
## waiting 0.075628 0.002219 34.09 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4965 on 270 degrees of freedom
## Multiple R-squared: 0.8115, Adjusted R-squared: 0.8108
## F-statistic: 1162 on 1 and 270 DF, p-value: < 2.2e-16
# Residuals : 잔차 오차
# Coefficients: 회귀계수(Estimate)
# (Intercept) : 절편(상수) : -1.874016
# 독립변수 waiting 회귀계수는 : 0.075628
# Pr(>\t\) 유의 확률입니다.
# 0.00000000000000022 < 유의수준 0.001
# 귀무가설 : 회귀계수는 0이다.
# 대립가설 : 회귀계수는 0이 아니다.
# 따라서 귀무가설 기각, 통계적으로 유의한 변수라고 합니다.
#표본크기-독립변수의 수-1 = 자유도
# n-1-1 = 270
# n = 272
# 30 DF : 1 DF (분자 자유도) = 회귀모형에 사용된 설명변수 개수
# 270 DF(분모 자유도) = 잔차의 자유도, 즉 n-p-1 => n: 관측치수 , p: 독립변수수
# Residual standard eroor : 0.4965
# 평균적으로 예측값과 실제값의 차이가 약 0.4965 정도라는 뜻
# 270 degrees of freedom = 자유도
# Adjusted R-squared: 0.8108 : 수정결정계수
format(2.2e-16, scientific=FALSE)
## [1] "0.00000000000000022"
#문제 2
data(pressure)
head(pressure)
## temperature pressure
## 1 0 0.0002
## 2 20 0.0012
## 3 40 0.0060
## 4 60 0.0300
## 5 80 0.0900
## 6 100 0.2700
model_2 <- lm(temperature ~ pressure, data = pressure) #독립변수 1개 단순선형 회귀
summary(model_2)
##
## Call:
## lm(formula = temperature ~ pressure, data = pressure)
##
## Residuals:
## Min 1Q Median 3Q Max
## -132.791 -62.813 6.507 67.033 90.759
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 132.79072 19.94314 6.658 4.03e-06 ***
## pressure 0.37969 0.07929 4.788 0.000171 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 75.56 on 17 degrees of freedom
## Multiple R-squared: 0.5742, Adjusted R-squared: 0.5492
## F-statistic: 22.93 on 1 and 17 DF, p-value: 0.000171
# Residuals : 잔차 오차
# Coefficients: 회귀계수(Estimate)
# (Intercept) : 절편(상수) : 132.79072
# 독립변수 pressure 회귀계수는 : 0.37969
# Pr(>\t\) 유의 확률입니다.
# 0.000171 < 유의수준 0.001
# 귀무가설 : 회귀계수는 0이다.
# 대립가설 : 회귀계수는 0이 아니다.
# 따라서 귀무가설 기각, 통계적으로 유의한 변수라고 합니다.
#표본크기-독립변수의 수-1 = 자유도
# n-1-1 = 17
# n=19
# 17 DF : 1 DF (분자 자유도) = 회귀모형에 사용된 설명변수 개수
# 17 DF(분모 자유도) = 잔차의 자유도, 즉 n-p-1 => n: 관측치수 , p: 독립변수수
# Residual standard eroor : 75.56
# 평균적으로 예측값과 실제값의 차이가 약 75.56 정도라는 뜻
# 30 degrees of freedom = 자유도
# Adjusted R-squared: 0.5492 : 수정결정계수
#
# 문제 3
data(women)
head(women)
## height weight
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
model_3 <- lm(height ~ weight, data = women) #독립변수 1개 단순선형 회귀
summary(model_3)
##
## Call:
## lm(formula = height ~ weight, data = women)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.83233 -0.26249 0.08314 0.34353 0.49790
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 25.723456 1.043746 24.64 2.68e-12 ***
## weight 0.287249 0.007588 37.85 1.09e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.44 on 13 degrees of freedom
## Multiple R-squared: 0.991, Adjusted R-squared: 0.9903
## F-statistic: 1433 on 1 and 13 DF, p-value: 1.091e-14
# Residuals : 잔차 오차
# Coefficients: 회귀계수(Estimate)
# (Intercept) : 절편(상수) : 25.723456
# 독립변수 weight 회귀계수는 : 0.287249
# Pr(>\t\) 유의 확률입니다.
# 0.00000000000001091< 유의수준 0.001
# 귀무가설 : 회귀계수는 0이다.
# 대립가설 : 회귀계수는 0이 아니다.
# 따라서 귀무가설 기각, 통계적으로 유의한 변수라고 합니다.
#표본크기-독립변수의 수-1 = 자유도
# n-1-1 = 13
# n = 15
# 13 DF : 1 DF (분자 자유도) = 회귀모형에 사용된 설명변수 개수
# 13 DF(분모 자유도) = 잔차의 자유도, 즉 n-p-1 => n: 관측치수 , p: 독립변수수
# Residual standard eroor : 0.44
# 평균적으로 예측값과 실제값의 차이가 약 0.44 정도라는 뜻
# 13 degrees of freedom = 자유도
# Adjusted R-squared: 0.9903 : 수정결정계수
format(1.091e-14, scientific=FALSE)
## [1] "0.00000000000001091"