Cars <- read.csv(file.choose()) # choose the Cars.csv data set
View(Cars)
dim(Cars) # Dimension of DataSet
## [1] 81 5
attach(Cars)
summary(Cars)
## HP MPG VOL SP
## Min. : 49.0 Min. :12.10 Min. : 50.00 Min. : 99.56
## 1st Qu.: 84.0 1st Qu.:27.86 1st Qu.: 89.00 1st Qu.:113.83
## Median :100.0 Median :35.15 Median :101.00 Median :118.21
## Mean :117.5 Mean :34.42 Mean : 98.77 Mean :121.54
## 3rd Qu.:140.0 3rd Qu.:39.53 3rd Qu.:113.00 3rd Qu.:126.40
## Max. :322.0 Max. :53.70 Max. :160.00 Max. :169.60
## WT
## Min. :15.71
## 1st Qu.:29.59
## Median :32.73
## Mean :32.41
## 3rd Qu.:37.39
## Max. :53.00
Cars[15:20,c(1,4)]
## HP SP
## 15 66 108.1854
## 16 73 111.1854
## 17 78 114.3693
## 18 92 117.5985
## 19 78 114.3693
## 20 90 118.4729
# Exploratory Data Analysis(60% of time)
# 1. Measures of Central Tendency
# 2. Measures of Dispersion
# 3. Third Moment Business decision
# 4. Fourth Moment Business decision
# 5. Probability distributions of variables
# 6. Graphical representations
# > Histogram,Box plot,Dot plot,Stem & Leaf plot,
# Bar plot
head(Cars)
## HP MPG VOL SP WT
## 1 49 53.70068 89 104.1854 28.76206
## 2 55 50.01340 92 105.4613 30.46683
## 3 55 50.01340 92 105.4613 30.19360
## 4 70 45.69632 92 113.4613 30.63211
## 5 53 50.50423 92 104.4613 29.88915
## 6 70 45.69632 89 113.1854 29.59177
colnames(Cars)
## [1] "HP" "MPG" "VOL" "SP" "WT"
# 7. Find the correlation b/n Output (MPG) & (HP,VOL,SP)-Scatter plot
pairs(Cars)
plot(Cars)
windows()
plot(Cars)
# 8. Correlation Coefficient matrix - Strength & Direction of Correlation
cor(Cars)
## HP MPG VOL SP WT
## HP 1.00000000 -0.7250383 0.07745947 0.9738481 0.07651307
## MPG -0.72503835 1.0000000 -0.52905658 -0.6871246 -0.52675909
## VOL 0.07745947 -0.5290566 1.00000000 0.1021700 0.99920308
## SP 0.97384807 -0.6871246 0.10217001 1.0000000 0.10243919
## WT 0.07651307 -0.5267591 0.99920308 0.1024392 1.00000000
library(caret)
## Warning: package 'caret' was built under R version 3.5.2
## Loading required package: lattice
## Warning: package 'lattice' was built under R version 3.5.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.2

inTrain <- createDataPartition(y = MPG, p=0.80,list = FALSE)
inTrain
## Resample1
## [1,] 1
## [2,] 2
## [3,] 4
## [4,] 5
## [5,] 6
## [6,] 7
## [7,] 8
## [8,] 9
## [9,] 10
## [10,] 11
## [11,] 13
## [12,] 14
## [13,] 16
## [14,] 18
## [15,] 19
## [16,] 21
## [17,] 22
## [18,] 23
## [19,] 25
## [20,] 26
## [21,] 27
## [22,] 28
## [23,] 29
## [24,] 30
## [25,] 31
## [26,] 32
## [27,] 34
## [28,] 35
## [29,] 36
## [30,] 38
## [31,] 39
## [32,] 40
## [33,] 41
## [34,] 44
## [35,] 45
## [36,] 46
## [37,] 47
## [38,] 48
## [39,] 49
## [40,] 51
## [41,] 52
## [42,] 53
## [43,] 54
## [44,] 55
## [45,] 56
## [46,] 57
## [47,] 58
## [48,] 59
## [49,] 61
## [50,] 62
## [51,] 63
## [52,] 64
## [53,] 65
## [54,] 66
## [55,] 67
## [56,] 69
## [57,] 71
## [58,] 72
## [59,] 73
## [60,] 76
## [61,] 77
## [62,] 78
## [63,] 79
## [64,] 80
## [65,] 81
train <- Cars[inTrain,]
test <- Cars[-inTrain,]
# The Linear Model of interest
m1 <- lm(MPG ~ . ,data = train)
coef(m1)
## (Intercept) HP VOL SP WT
## 32.7843331 -0.1987660 -0.2403113 0.3746858 0.1026374
summary(m1)
##
## Call:
## lm(formula = MPG ~ ., data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.8528 -3.0153 -0.3958 2.7671 14.9319
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 32.78433 16.98726 1.930 0.0583 .
## HP -0.19877 0.04479 -4.438 3.95e-05 ***
## VOL -0.24031 0.65221 -0.368 0.7138
## SP 0.37469 0.18196 2.059 0.0438 *
## WT 0.10264 1.94593 0.053 0.9581
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.675 on 60 degrees of freedom
## Multiple R-squared: 0.7529, Adjusted R-squared: 0.7364
## F-statistic: 45.69 on 4 and 60 DF, p-value: < 2.2e-16
# Prediction based on only Volume
model.carV <- lm(MPG ~ VOL,data = train)
summary(model.carV) # Volume became significant
##
## Call:
## lm(formula = MPG ~ VOL, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -24.2128 -4.7209 0.2076 5.5118 17.4349
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 53.66760 4.60011 11.667 < 2e-16 ***
## VOL -0.19553 0.04594 -4.256 7.05e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.087 on 63 degrees of freedom
## Multiple R-squared: 0.2233, Adjusted R-squared: 0.211
## F-statistic: 18.11 on 1 and 63 DF, p-value: 7.046e-05
# Prediction based on only Weight
model.carW <- lm(MPG ~ WT,data = train)
summary(model.carW) # Weight became significant
##
## Call:
## lm(formula = MPG ~ WT, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -24.2774 -4.8246 -0.1079 5.3410 17.2307
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 53.1104 4.5084 11.780 < 2e-16 ***
## WT -0.5786 0.1371 -4.221 7.96e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.102 on 63 degrees of freedom
## Multiple R-squared: 0.2204, Adjusted R-squared: 0.2081
## F-statistic: 17.82 on 1 and 63 DF, p-value: 7.96e-05
# Prediction based on Volume and Weight
model.carVW <- lm(MPG ~ VOL + WT,data = train)
summary(model.carVW) # Both became Insignificant
##
## Call:
## lm(formula = MPG ~ VOL + WT, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -23.7798 -4.8474 0.0047 5.3759 18.1411
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 55.0285 5.2055 10.571 1.67e-15 ***
## VOL -0.8283 1.1116 -0.745 0.459
## WT 1.8861 3.3107 0.570 0.571
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.131 on 62 degrees of freedom
## Multiple R-squared: 0.2274, Adjusted R-squared: 0.2024
## F-statistic: 9.122 on 2 and 62 DF, p-value: 0.0003367
# It is Better to delete influential observations rather than deleting entire column which is
# costliest process
# Deletion Diagnostics for identifying influential observations
influence.measures(m1)
## Influence measures of
## lm(formula = MPG ~ ., data = train) :
##
## dfb.1_ dfb.HP dfb.VOL dfb.SP dfb.WT dffit cov.r
## 1 1.85e-03 -1.01e-01 0.371256 2.08e-02 -3.76e-01 0.606719 0.756
## 2 1.53e-01 5.41e-02 -0.238951 -1.06e-01 2.37e-01 0.407285 0.904
## 4 -4.80e-02 -8.67e-02 -0.130739 7.30e-02 1.29e-01 0.205683 1.124
## 5 7.73e-02 -5.61e-04 0.187179 -5.96e-02 -1.89e-01 0.412730 0.869
## 6 -3.68e-02 -7.03e-02 -0.102057 5.86e-02 1.00e-01 0.167146 1.133
## 7 1.20e-01 2.98e-02 -0.122046 -8.15e-02 1.20e-01 0.348362 0.894
## 8 -8.09e-02 -4.82e-02 -0.021506 6.14e-02 2.58e-02 -0.158552 1.233
## 9 -1.12e-01 -7.13e-02 0.075834 8.48e-02 -7.14e-02 -0.179708 1.261
## 10 -3.31e-02 -4.40e-02 -0.005511 3.91e-02 4.88e-03 0.064679 1.121
## 11 1.32e-02 -1.78e-02 -0.059434 4.10e-03 5.80e-02 0.127643 1.085
## 13 2.33e-02 2.62e-02 0.008862 -2.56e-02 -8.66e-03 -0.032889 1.193
## 14 1.44e-02 -1.69e-02 -0.063760 3.23e-03 6.23e-02 0.129731 1.086
## 16 3.27e-02 -3.64e-03 -0.130542 -1.00e-02 1.29e-01 0.173623 1.116
## 18 1.71e-01 3.13e-01 0.085409 -2.94e-01 -5.85e-02 -0.737076 0.865
## 19 -2.19e-02 -3.38e-02 -0.009251 2.86e-02 8.50e-03 0.059273 1.117
## 21 8.21e-03 8.95e-03 -0.005370 -8.45e-03 5.42e-03 -0.011815 1.143
## 22 -1.02e-02 -2.90e-02 0.135899 2.86e-03 -1.33e-01 0.239479 1.010
## 23 -1.25e-02 -1.26e-02 0.014241 1.21e-02 -1.43e-02 0.018925 1.206
## 25 6.38e-02 7.01e-02 -0.071641 -6.65e-02 7.30e-02 -0.107734 1.151
## 26 -4.02e-02 8.72e-02 -0.002365 -6.32e-02 2.60e-02 -0.637519 0.866
## 27 -1.70e-01 -1.62e-01 0.164841 1.56e-01 -1.63e-01 0.239019 1.190
## 28 6.19e-03 8.03e-03 0.007351 -7.48e-03 -7.30e-03 -0.014743 1.145
## 29 3.68e-01 3.05e-01 -0.218067 -3.51e-01 2.23e-01 0.454521 1.108
## 30 1.03e-02 1.21e-02 0.013888 -1.17e-02 -1.40e-02 -0.025565 1.148
## 31 -4.17e-02 -3.95e-02 0.206560 2.14e-02 -2.03e-01 0.268129 1.079
## 32 2.94e-02 1.79e-02 -0.016498 -2.59e-02 1.71e-02 0.073455 1.096
## 34 -2.92e-02 -3.33e-02 -0.047019 3.17e-02 4.80e-02 0.084846 1.141
## 35 6.18e-03 7.86e-04 0.085882 -1.01e-02 -8.53e-02 0.113558 1.136
## 36 -1.29e-03 -2.06e-03 0.005642 1.32e-03 -5.64e-03 0.009320 1.121
## 38 -6.88e-03 1.04e-02 -0.097219 -1.76e-03 9.98e-02 -0.174921 1.039
## 39 -9.63e-02 -5.62e-02 0.220238 6.38e-02 -2.18e-01 -0.265354 1.071
## 40 1.74e-01 1.75e-01 -0.045675 -1.85e-01 4.88e-02 -0.236439 1.027
## 41 5.37e-03 2.98e-03 -0.016957 -5.30e-03 1.77e-02 0.038033 1.120
## 44 -2.09e-02 -1.01e-02 -0.130616 2.02e-02 1.32e-01 -0.176392 1.105
## 45 -7.73e-04 -3.56e-04 -0.014785 1.62e-03 1.47e-02 -0.019640 1.144
## 46 -1.16e-02 -4.47e-03 0.020848 7.88e-03 -2.10e-02 -0.054791 1.096
## 47 -1.58e-03 -1.81e-03 0.001026 1.27e-03 -8.42e-04 0.009638 1.113
## 48 -4.21e-03 -2.24e-03 0.004393 3.61e-03 -4.59e-03 -0.018982 1.108
## 49 1.89e-01 1.96e-01 -0.067775 -2.08e-01 7.33e-02 -0.286795 0.980
## 51 -9.24e-02 -8.73e-02 0.033725 9.10e-02 -3.51e-02 -0.139014 1.059
## 52 -1.16e-01 -1.06e-01 0.112709 1.09e-01 -1.14e-01 -0.178893 1.075
## 53 -1.19e-03 4.20e-04 0.010904 -6.67e-04 -1.05e-02 0.015374 1.177
## 54 1.51e-01 1.26e-01 0.095269 -1.51e-01 -9.63e-02 -0.243394 1.186
## 55 4.37e-02 3.28e-02 0.001280 -4.02e-02 -2.11e-03 -0.072066 1.128
## 56 1.71e-02 1.10e-02 -0.024517 -1.20e-02 2.35e-02 -0.043519 1.149
## 57 -2.63e-01 -2.35e-01 0.050367 2.54e-01 -5.11e-02 -0.298036 1.054
## 58 -4.75e-02 -5.37e-02 -0.132054 5.82e-02 1.31e-01 -0.188619 1.085
## 59 -2.01e-01 -1.83e-01 -0.061625 2.00e-01 6.08e-02 -0.279504 1.011
## 61 1.79e-02 1.10e-02 0.079059 -1.88e-02 -8.05e-02 -0.123634 1.115
## 62 -1.45e-01 -1.65e-01 -0.107214 1.71e-01 1.01e-01 -0.275111 1.082
## 63 -2.45e-02 -3.62e-02 0.028793 3.33e-02 -3.19e-02 -0.095603 1.151
## 64 -6.29e-02 -7.92e-02 0.060588 7.42e-02 -6.52e-02 -0.159951 1.110
## 65 -4.76e-02 -6.15e-02 0.072079 5.46e-02 -7.54e-02 -0.135439 1.131
## 66 1.38e-01 1.30e-01 0.067438 -1.18e-01 -7.46e-02 0.282127 1.215
## 67 -5.09e-02 -6.74e-02 0.137682 5.29e-02 -1.41e-01 -0.190775 1.132
## 69 5.05e-03 -9.72e-03 -0.008875 3.30e-03 6.99e-03 -0.068016 1.130
## 71 5.69e-01 4.17e-01 -0.293159 -6.24e-01 3.28e-01 -1.354058 0.980
## 72 -1.31e-02 -3.94e-03 0.031542 6.37e-03 -3.04e-02 0.046269 1.234
## 73 -5.66e-05 8.47e-06 0.000104 1.31e-05 -9.45e-05 0.000301 1.167
## 76 -7.21e-02 -9.95e-02 0.065927 8.68e-02 -7.07e-02 -0.172402 1.170
## 77 3.90e-02 4.01e-01 -0.297611 6.58e-02 2.41e-01 2.600850 0.395
## 78 -6.95e-04 1.85e-02 -0.009016 -5.39e-03 1.00e-02 0.072230 1.188
## 79 2.32e-01 3.23e-01 0.131081 -2.03e-01 -1.51e-01 0.866254 1.065
## 80 -2.57e-01 -3.69e-02 -0.157343 2.01e-01 1.65e-01 0.845023 1.034
## 81 -3.99e-01 -4.85e-01 -0.007334 4.37e-01 1.04e-03 -0.545801 1.308
## cook.d hat inf
## 1 6.87e-02 0.0649
## 2 3.22e-02 0.0540
## 4 8.53e-03 0.0743
## 5 3.28e-02 0.0488
## 6 5.65e-03 0.0697
## 7 2.35e-02 0.0405
## 8 5.10e-03 0.1304
## 9 6.55e-03 0.1508 *
## 10 8.49e-04 0.0381
## 11 3.29e-03 0.0350
## 13 2.20e-04 0.0895
## 14 3.40e-03 0.0361
## 16 6.08e-03 0.0621
## 18 1.03e-01 0.1130
## 19 7.13e-04 0.0344
## 21 2.84e-05 0.0485
## 22 1.14e-02 0.0401
## 23 7.28e-05 0.0986
## 25 2.35e-03 0.0679
## 26 7.75e-02 0.0929
## 27 1.15e-02 0.1185
## 28 4.42e-05 0.0507
## 29 4.10e-02 0.1277
## 30 1.33e-04 0.0532
## 31 1.44e-02 0.0698
## 32 1.09e-03 0.0250
## 34 1.46e-03 0.0563
## 35 2.61e-03 0.0593
## 36 1.77e-05 0.0303
## 38 6.13e-03 0.0318
## 39 1.41e-02 0.0659
## 40 1.11e-02 0.0437
## 41 2.94e-04 0.0328
## 44 6.27e-03 0.0573
## 45 7.84e-05 0.0494
## 46 6.09e-04 0.0201
## 47 1.89e-05 0.0232
## 48 7.33e-05 0.0199
## 49 1.62e-02 0.0440
## 51 3.89e-03 0.0284
## 52 6.43e-03 0.0449
## 53 4.81e-05 0.0764
## 54 1.20e-02 0.1169
## 55 1.05e-03 0.0450
## 56 3.85e-04 0.0561
## 57 1.77e-02 0.0682
## 58 7.16e-03 0.0512
## 59 1.55e-02 0.0499
## 61 3.09e-03 0.0486
## 62 1.51e-02 0.0728
## 63 1.85e-03 0.0656
## 64 5.17e-03 0.0554
## 65 3.71e-03 0.0612
## 66 1.61e-02 0.1410
## 67 7.35e-03 0.0749
## 69 9.39e-04 0.0457
## 71 3.43e-01 0.2655 *
## 72 4.35e-04 0.1197
## 73 1.84e-08 0.0678
## 76 6.02e-03 0.0931
## 77 1.05e+00 0.2730 *
## 78 1.06e-03 0.0883
## 79 1.45e-01 0.2016 *
## 80 1.38e-01 0.1866
## 81 5.96e-02 0.2338 *
library(car)
## Warning: package 'car' was built under R version 3.5.2
## Loading required package: carData
## Warning: package 'carData' was built under R version 3.5.2
## plotting Influential measures
windows()
influenceIndexPlot(m1) # index plots for infuence measures

influencePlot(m1) # A user friendly representation of the above

## StudRes Hat CookD
## 1 2.302655 0.06491824 0.0686958
## 71 -2.252378 0.26546356 0.3433832
## 77 4.244249 0.27300038 1.0540088
# Regression after deleting the 77th observation, which is influential observation
model.car1 <- lm(MPG ~ VOL + SP + HP + WT,data =train[-77,])
summary(model.car1)
##
## Call:
## lm(formula = MPG ~ VOL + SP + HP + WT, data = train[-77, ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.8528 -3.0153 -0.3958 2.7671 14.9319
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 32.78433 16.98726 1.930 0.0583 .
## VOL -0.24031 0.65221 -0.368 0.7138
## SP 0.37469 0.18196 2.059 0.0438 *
## HP -0.19877 0.04479 -4.438 3.95e-05 ***
## WT 0.10264 1.94593 0.053 0.9581
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.675 on 60 degrees of freedom
## Multiple R-squared: 0.7529, Adjusted R-squared: 0.7364
## F-statistic: 45.69 on 4 and 60 DF, p-value: < 2.2e-16
# Regression after deleting the 77th & 71st Observations
model.car3 <-lm(MPG ~ VOL + SP + HP + WT,data=train[-c(71,77),])
summary(model.car3)
##
## Call:
## lm(formula = MPG ~ VOL + SP + HP + WT, data = train[-c(71, 77),
## ])
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.8528 -3.0153 -0.3958 2.7671 14.9319
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 32.78433 16.98726 1.930 0.0583 .
## VOL -0.24031 0.65221 -0.368 0.7138
## SP 0.37469 0.18196 2.059 0.0438 *
## HP -0.19877 0.04479 -4.438 3.95e-05 ***
## WT 0.10264 1.94593 0.053 0.9581
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.675 on 60 degrees of freedom
## Multiple R-squared: 0.7529, Adjusted R-squared: 0.7364
## F-statistic: 45.69 on 4 and 60 DF, p-value: < 2.2e-16
## Variance Inflation factor to check collinearity b/n variables
vif(m1)
## HP VOL SP WT
## 20.95584 603.24874 20.97242 605.44129
## vif>10 then there exists collinearity among all the variables
## Added Variable plot to check correlation b/n variables and o/p variable
windows()
avPlots(m1)

## VIF and AV plot has given us an indication to delete "wt" variable
finalmodel <- lm(MPG ~ WT + SP + HP,data = train)
summary(finalmodel)
##
## Call:
## lm(formula = MPG ~ WT + SP + HP, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.925 -2.722 -0.333 2.467 15.035
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 31.07343 16.22414 1.915 0.0602 .
## WT -0.61373 0.08049 -7.625 1.95e-10 ***
## SP 0.38771 0.17723 2.188 0.0325 *
## HP -0.20206 0.04358 -4.637 1.92e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.641 on 61 degrees of freedom
## Multiple R-squared: 0.7523, Adjusted R-squared: 0.7401
## F-statistic: 61.76 on 3 and 61 DF, p-value: < 2.2e-16
## Final model
finalmodel <- lm(MPG ~ VOL + SP + HP,data = train)
summary(finalmodel)
##
## Call:
## lm(formula = MPG ~ VOL + SP + HP, data = train)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.8462 -2.9778 -0.4368 2.8062 14.9438
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 32.53728 16.19474 2.009 0.0490 *
## VOL -0.20594 0.02695 -7.642 1.82e-10 ***
## SP 0.37664 0.17671 2.131 0.0371 *
## HP -0.19926 0.04345 -4.586 2.30e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.636 on 61 degrees of freedom
## Multiple R-squared: 0.7528, Adjusted R-squared: 0.7407
## F-statistic: 61.94 on 3 and 61 DF, p-value: < 2.2e-16
windows()
avPlots(finalmodel)

# Evaluate model LINE assumptions
windows()
plot(finalmodel)




m2 <- lm(MPG ~ . ,data = Cars)
vif(m2)
## HP VOL SP WT
## 19.92659 638.80608 20.00764 639.53382
windows()
avPlots(m2)

summary(m2)
##
## Call:
## lm(formula = MPG ~ ., data = Cars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.6320 -2.9944 -0.3705 2.2149 15.6179
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 30.67734 14.90030 2.059 0.0429 *
## HP -0.20544 0.03922 -5.239 1.4e-06 ***
## VOL -0.33605 0.56864 -0.591 0.5563
## SP 0.39563 0.15826 2.500 0.0146 *
## WT 0.40057 1.69346 0.237 0.8136
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.488 on 76 degrees of freedom
## Multiple R-squared: 0.7705, Adjusted R-squared: 0.7585
## F-statistic: 63.8 on 4 and 76 DF, p-value: < 2.2e-16
library(MASS)
## Warning: package 'MASS' was built under R version 3.5.2
stepAIC(m2)
## Start: AIC=248.06
## MPG ~ HP + VOL + SP + WT
##
## Df Sum of Sq RSS AIC
## - WT 1 1.13 1531.8 246.12
## - VOL 1 7.03 1537.7 246.43
## <none> 1530.7 248.06
## - SP 1 125.87 1656.5 252.46
## - HP 1 552.74 2083.4 271.03
##
## Step: AIC=246.12
## MPG ~ HP + VOL + SP
##
## Df Sum of Sq RSS AIC
## <none> 1531.8 246.12
## - SP 1 131.46 1663.3 250.79
## - HP 1 570.08 2101.9 269.75
## - VOL 1 1585.81 3117.6 301.68
##
## Call:
## lm(formula = MPG ~ HP + VOL + SP, data = Cars)
##
## Coefficients:
## (Intercept) HP VOL SP
## 29.9234 -0.2067 -0.2017 0.4007
#Residual plots,QQplot,std-Residuals Vs Fitted,Cook's Distance
windows()
qqPlot(finalmodel)

## 1 77
## 1 61
# QQ plot of studentized residuals helps in identifying outlier