# 귀무가설 : 회귀계수는 0이다.
# 대립가설 : 회귀계수는 0이 아니다.
# 따라서 귀무가설 기각, 통계적으로 유의한 변수라고 한다.
# Multiple R-squared: 0.8115, Adjusted R-squared: 0.8108
# 결정계수는 1과 가까우므로 모델이 데이터를 잘설명한다고 할 수 있다.
# 표본크기 - 독립변수의 수-1 = 자유도
# n-1-1 = 270
# 1 and 270 DF : 1 DF (분자 자유도) = 회귀모형에 사용된 설명변수 개수
# 270 DF (분모 자유도) = 잔차의 자유도, 즉 n(표본의 크기)-p(독립변수 수,1)-1
# n = 272
# Residual standard error: 0.4965
# 평균적으로 예측값과 실제값의 차이가 약 0.4965 정도라는 뜻
# 270 degrees of freedom = 자유도
# Adjusted R-squared: 0.8108 : 수정된 결정계수
str(faithful)
## 'data.frame': 272 obs. of 2 variables:
## $ eruptions: num 3.6 1.8 3.33 2.28 4.53 ...
## $ waiting : num 79 54 74 62 85 55 88 85 51 85 ...
## 'data.frame': 272 obs. of 2 variables:
## $ eruptions: num 3.6 1.8 3.33 2.28 4.53 ...
## $ waiting : num 79 54 74 62 85 55 88 85 51 85 ...
data(pressure)
summary(pressure)
## temperature pressure
## Min. : 0 Min. : 0.0002
## 1st Qu.: 90 1st Qu.: 0.1800
## Median :180 Median : 8.8000
## Mean :180 Mean :124.3367
## 3rd Qu.:270 3rd Qu.:126.5000
## Max. :360 Max. :806.0000
## temperature pressure
## Min. : 0 Min. : 0.0002
## 1st Qu.: 90 1st Qu.: 0.1800
## Median :180 Median : 8.8000
## Mean :180 Mean :124.3367
## 3rd Qu.:270 3rd Qu.:126.5000
## Max. :360 Max. :806.0000
model2 <- lm(pressure~temperature, data = pressure)
summary(model2)
##
## Call:
## lm(formula = pressure ~ temperature, data = pressure)
##
## Residuals:
## Min 1Q Median 3Q Max
## -158.08 -117.06 -32.84 72.30 409.43
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -147.8989 66.5529 -2.222 0.040124 *
## temperature 1.5124 0.3158 4.788 0.000171 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 150.8 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
##
## Call:
## lm(formula = pressure ~ temperature, data = pressure)
##
## Residuals:
## Min 1Q Median 3Q Max
## -158.08 -117.06 -32.84 72.30 409.43
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -147.8989 66.5529 -2.222 0.040124 *
## temperature 1.5124 0.3158 4.788 0.000171 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 150.8 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) : 절편(상수) : -147.8989
# 독립변수 temperature 회귀계수는: 1.5124
# Pr(>|t|) 유의확률입니다.
# 0.000171 < 유의수준 0.05
# 귀무가설 : 회귀계수는 0이다.
# 대립가설 : 회귀계수는 0이 아니다.
# 따라서 귀무가설 기각, 통계적으로 유의한 변수라고 한다.
# Multiple R-squared: 0.5742, Adjusted R-squared: 0.5492
# 결정계수는 중간이므로 모델이 데이터에 대한 설명이 애매하다
# 표본크기 - 독립변수의 수-1 = 자유도
# n-1-1 = 17
# 1 and 17 DF : 1 DF (분자 자유도) = 회귀모형에 사용된 설명변수 개수
# 17 DF (분모 자유도) = 잔차의 자유도, 즉 n(표본의 크기)-p(독립변수 수,1)-1
# n = 19
# Residual standard error: 150.8
# 평균적으로 예측값과 실제값의 차이가 약 150.8 정도라는 뜻
# 17 degrees of freedom = 자유도
# Adjusted R-squared: 0.5492 : 수정된 결정계수
str(pressure)
## 'data.frame': 19 obs. of 2 variables:
## $ temperature: num 0 20 40 60 80 100 120 140 160 180 ...
## $ pressure : num 0.0002 0.0012 0.006 0.03 0.09 0.27 0.75 1.85 4.2 8.8 ...
## 'data.frame': 19 obs. of 2 variables:
## $ temperature: num 0 20 40 60 80 100 120 140 160 180 ...
## $ pressure : num 0.0002 0.0012 0.006 0.03 0.09 0.27 0.75 1.85 4.2 8.8 ...
data(women)
summary(women)
## height weight
## Min. :58.0 Min. :115.0
## 1st Qu.:61.5 1st Qu.:124.5
## Median :65.0 Median :135.0
## Mean :65.0 Mean :136.7
## 3rd Qu.:68.5 3rd Qu.:148.0
## Max. :72.0 Max. :164.0
## height weight
## Min. :58.0 Min. :115.0
## 1st Qu.:61.5 1st Qu.:124.5
## Median :65.0 Median :135.0
## Mean :65.0 Mean :136.7
## 3rd Qu.:68.5 3rd Qu.:148.0
## Max. :72.0 Max. :164.0
model3 <- lm(weight~height, data = women)
summary(model3)
##
## Call:
## lm(formula = weight ~ height, data = women)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.7333 -1.1333 -0.3833 0.7417 3.1167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -87.51667 5.93694 -14.74 1.71e-09 ***
## height 3.45000 0.09114 37.85 1.09e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.525 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
##
## Call:
## lm(formula = weight ~ height, data = women)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.7333 -1.1333 -0.3833 0.7417 3.1167
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -87.51667 5.93694 -14.74 1.71e-09 ***
## height 3.45000 0.09114 37.85 1.09e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.525 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) : 절편(상수) : -87.51667
# 독립변수 temperature 회귀계수는: 3.45000
# Pr(>|t|) 유의확률입니다.
format(1.09e-14, scientific=FALSE)
## [1] "0.0000000000000109"
## [1] "0.0000000000000109"
# 0.0000000000000109 < 유의수준 0.05
# 귀무가설 : 회귀계수는 0이다.
# 대립가설 : 회귀계수는 0이 아니다.
# 따라서 귀무가설 기각, 통계적으로 유의한 변수라고 한다.
# Multiple R-squared: 0.991, Adjusted R-squared: 0.9903
# 결정계수는 1과 가까우므로 모델이 데이터를 잘설명한다고 할 수 있다.
# Multiple R-squared(결정계수)
# 회귀분석에서 모델이 종속변수의 변동을 얼마나 잘 설명하는지를 나타내는 지표
# 결정계수 0~1사이의 값을 갖는다.
# 1에 가까울수록 선형회귀 직선위에 관측치가 잘 모여있다를 의미
# 결정계수가 1이라면 선형회귀 직선위에 모든 관측기가 있음을 의미함.
# 3개의 모델중 결정계수가 제일 큰 모델은?
# model3 <- lm(weight~height, data = women) = 0.991로 우수 했음.
# 일반적으로 결정계수값이 0.75이상이면 좋은 설명력을 가진 모형이다.
# Std. Error : 표준오차
# Estimate / Std. Error = t-value
3.45000/0.09114
## [1] 37.85385
## [1] 37.85385
# t 통계량의 절대값이 클수록 통계적으로 유의(significance)하다.
# Signif. codes : 유의수준
# Pr(>|t|)옆에 '*'가 있으면 유의수준 0.05에서 유의한 변수이다.
# '*'가 많을수록 더울 엄격하게 유의한 변수이다.
# 회귀모형의 유의성 검정 판단에 필요한 것은 F-statistic와 p-value이다.
# 귀무가설 : 모든 회귀계수는 0이다.
# 대립가설 : 적어도 하나의 회귀계수는 0이 아니다.
# 0.0000000000000109 < 유의수준 0.05
# 귀무가설 기각, 통계적으로 유의한 모형이라 한다.
# 결과적으로 회귀계수 하나라도 0이 아니면 통계적으로 유의한 모형이다.
# 표본크기 - 독립변수의 수-1 = 자유도
# n-1-1 = 30
# 1 and 13 DF : 1 DF (분자 자유도) = 회귀모형에 사용된 설명변수 개수
# 13 DF (분모 자유도) = 잔차의 자유도, 즉 n(표본의 크기)-p(독립변수 수,1)-1
# n = 15
# Residual standard error: 1.525
# 평균적으로 예측값과 실제값의 차이가 약 3.863 정도라는 뜻
# 13 degrees of freedom = 자유도
# Adjusted R-squared: 0.9903 : 수정된 결정계수
str(women)
## 'data.frame': 15 obs. of 2 variables:
## $ height: num 58 59 60 61 62 63 64 65 66 67 ...
## $ weight: num 115 117 120 123 126 129 132 135 139 142 ...
## 'data.frame': 15 obs. of 2 variables:
## $ height: num 58 59 60 61 62 63 64 65 66 67 ...
## $ weight: num 115 117 120 123 126 129 132 135 139 142 ...