To perform multivariate regression analysis using the attitude dataset and test assumptions.
data(attitude)
head(attitude)
## rating complaints privileges learning raises critical advance
## 1 43 51 30 39 61 92 45
## 2 63 64 51 54 63 73 47
## 3 71 70 68 69 76 86 48
## 4 61 63 45 47 54 84 35
## 5 81 78 56 66 71 83 47
## 6 43 55 49 44 54 49 34
model_full <- lm(rating ~ ., data = attitude)
summary(model_full)
##
## Call:
## lm(formula = rating ~ ., data = attitude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.9418 -4.3555 0.3158 5.5425 11.5990
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.78708 11.58926 0.931 0.361634
## complaints 0.61319 0.16098 3.809 0.000903 ***
## privileges -0.07305 0.13572 -0.538 0.595594
## learning 0.32033 0.16852 1.901 0.069925 .
## raises 0.08173 0.22148 0.369 0.715480
## critical 0.03838 0.14700 0.261 0.796334
## advance -0.21706 0.17821 -1.218 0.235577
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.068 on 23 degrees of freedom
## Multiple R-squared: 0.7326, Adjusted R-squared: 0.6628
## F-statistic: 10.5 on 6 and 23 DF, p-value: 1.24e-05
model_best <- step(model_full)
## Start: AIC=123.36
## rating ~ complaints + privileges + learning + raises + critical +
## advance
##
## Df Sum of Sq RSS AIC
## - critical 1 3.41 1152.4 121.45
## - raises 1 6.80 1155.8 121.54
## - privileges 1 14.47 1163.5 121.74
## - advance 1 74.11 1223.1 123.24
## <none> 1149.0 123.36
## - learning 1 180.50 1329.5 125.74
## - complaints 1 724.80 1873.8 136.04
##
## Step: AIC=121.45
## rating ~ complaints + privileges + learning + raises + advance
##
## Df Sum of Sq RSS AIC
## - raises 1 10.61 1163.0 119.73
## - privileges 1 14.16 1166.6 119.82
## - advance 1 71.27 1223.7 121.25
## <none> 1152.4 121.45
## - learning 1 177.74 1330.1 123.75
## - complaints 1 724.70 1877.1 134.09
##
## Step: AIC=119.73
## rating ~ complaints + privileges + learning + advance
##
## Df Sum of Sq RSS AIC
## - privileges 1 16.10 1179.1 118.14
## - advance 1 61.60 1224.6 119.28
## <none> 1163.0 119.73
## - learning 1 197.03 1360.0 122.42
## - complaints 1 1165.94 2328.9 138.56
##
## Step: AIC=118.14
## rating ~ complaints + learning + advance
##
## Df Sum of Sq RSS AIC
## - advance 1 75.54 1254.7 118.00
## <none> 1179.1 118.14
## - learning 1 186.12 1365.2 120.54
## - complaints 1 1259.91 2439.0 137.94
##
## Step: AIC=118
## rating ~ complaints + learning
##
## Df Sum of Sq RSS AIC
## <none> 1254.7 118.00
## - learning 1 114.73 1369.4 118.63
## - complaints 1 1370.91 2625.6 138.16
summary(model_best)
##
## Call:
## lm(formula = rating ~ complaints + learning, data = attitude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.5568 -5.7331 0.6701 6.5341 10.3610
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.8709 7.0612 1.398 0.174
## complaints 0.6435 0.1185 5.432 9.57e-06 ***
## learning 0.2112 0.1344 1.571 0.128
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.817 on 27 degrees of freedom
## Multiple R-squared: 0.708, Adjusted R-squared: 0.6864
## F-statistic: 32.74 on 2 and 27 DF, p-value: 6.058e-08
model_best <- lm(rating ~ complaints + learning, data = attitude)
summary(model_best)
##
## Call:
## lm(formula = rating ~ complaints + learning, data = attitude)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.5568 -5.7331 0.6701 6.5341 10.3610
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.8709 7.0612 1.398 0.174
## complaints 0.6435 0.1185 5.432 9.57e-06 ***
## learning 0.2112 0.1344 1.571 0.128
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.817 on 27 degrees of freedom
## Multiple R-squared: 0.708, Adjusted R-squared: 0.6864
## F-statistic: 32.74 on 2 and 27 DF, p-value: 6.058e-08
par(mfrow = c(2,2))
plot(model_best)
library(car)
## Warning: package 'car' was built under R version 4.5.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.5.3
vif(model_best)
## complaints learning
## 1.553021 1.553021
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.5.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.5.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
dwtest(model_best)
##
## Durbin-Watson test
##
## data: model_best
## DW = 1.9582, p-value = 0.439
## alternative hypothesis: true autocorrelation is greater than 0