attach(swiss)
bs = lm(Fertility~Infant.Mortality)
summary(bs)
## 
## Call:
## lm(formula = Fertility ~ Infant.Mortality)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -31.672  -5.687  -0.381   7.239  28.565 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)   
## (Intercept)       34.5155    11.7113   2.947  0.00507 **
## Infant.Mortality   1.7865     0.5812   3.074  0.00359 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 11.48 on 45 degrees of freedom
## Multiple R-squared:  0.1735, Adjusted R-squared:  0.1552 
## F-statistic: 9.448 on 1 and 45 DF,  p-value: 0.003585
# 잔차의 독립성
library(car)
## Warning: 패키지 'car'는 R 버전 4.2.3에서 작성되었습니다
## 필요한 패키지를 로딩중입니다: carData
## Warning: 패키지 'carData'는 R 버전 4.2.3에서 작성되었습니다
sreg.res1=residuals(bs)
durbinWatsonTest(sreg.res1)
## [1] 1.010858
# 잔차의 등분산성
par(mfrow=c(2,2))
plot(bs)

# 잔차의 정규성
shapiro.test(sreg.res1)
## 
##  Shapiro-Wilk normality test
## 
## data:  sreg.res1
## W = 0.97508, p-value = 0.4076