it there any problem for the following multiple linear
regression?
fit<- lm(mpg ~ disp + hp + drat + wt + qsec, data = mtcars)
summary(fit)
##
## Call:
## lm(formula = mpg ~ disp + hp + drat + wt + qsec, data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.5404 -1.6701 -0.4264 1.1320 5.4996
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 16.53357 10.96423 1.508 0.14362
## disp 0.00872 0.01119 0.779 0.44281
## hp -0.02060 0.01528 -1.348 0.18936
## drat 2.01578 1.30946 1.539 0.13579
## wt -4.38546 1.24343 -3.527 0.00158 **
## qsec 0.64015 0.45934 1.394 0.17523
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.558 on 26 degrees of freedom
## Multiple R-squared: 0.8489, Adjusted R-squared: 0.8199
## F-statistic: 29.22 on 5 and 26 DF, p-value: 6.892e-10
library(car)
## 载入需要的程辑包:carData
vif(fit)
## disp hp drat wt qsec
## 9.110869 5.201833 2.322343 7.012686 3.191939
for the following, which model is better?
fit1<- lm(mpg ~ disp + hp + drat + qsec, data = mtcars)
fit2<- lm(mpg ~ disp + hp + wt + qsec, data = mtcars)
AIC(fit1, fit2)
## df AIC
## fit1 6 168.7896
## fit2 6 159.0696
write down the final model from the following output.
library(MASS)
fit<- lm(mpg ~ disp + hp + drat + wt + qsec, data = mtcars)
stepAIC(fit, direction = "backward")
## Start: AIC=65.47
## mpg ~ disp + hp + drat + wt + qsec
##
## Df Sum of Sq RSS AIC
## - disp 1 3.974 174.10 64.205
## <none> 170.13 65.466
## - hp 1 11.886 182.01 65.627
## - qsec 1 12.708 182.84 65.772
## - drat 1 15.506 185.63 66.258
## - wt 1 81.394 251.52 75.978
##
## Step: AIC=64.21
## mpg ~ hp + drat + wt + qsec
##
## Df Sum of Sq RSS AIC
## - hp 1 9.418 183.52 63.891
## - qsec 1 9.578 183.68 63.919
## <none> 174.10 64.205
## - drat 1 11.956 186.06 64.331
## - wt 1 113.882 287.99 78.310
##
## Step: AIC=63.89
## mpg ~ drat + wt + qsec
##
## Df Sum of Sq RSS AIC
## <none> 183.52 63.891
## - drat 1 11.942 195.46 63.908
## - qsec 1 85.720 269.24 74.156
## - wt 1 275.686 459.21 91.241
##
## Call:
## lm(formula = mpg ~ drat + wt + qsec, data = mtcars)
##
## Coefficients:
## (Intercept) drat wt qsec
## 11.3945 1.6561 -4.3978 0.9462