Multiple Liner Regression Model

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,]         9
##  [8,]        10
##  [9,]        11
## [10,]        13
## [11,]        15
## [12,]        17
## [13,]        18
## [14,]        19
## [15,]        21
## [16,]        22
## [17,]        23
## [18,]        24
## [19,]        25
## [20,]        26
## [21,]        27
## [22,]        28
## [23,]        29
## [24,]        30
## [25,]        32
## [26,]        33
## [27,]        34
## [28,]        35
## [29,]        36
## [30,]        38
## [31,]        39
## [32,]        40
## [33,]        41
## [34,]        42
## [35,]        43
## [36,]        44
## [37,]        45
## [38,]        46
## [39,]        47
## [40,]        48
## [41,]        51
## [42,]        52
## [43,]        54
## [44,]        55
## [45,]        56
## [46,]        57
## [47,]        59
## [48,]        60
## [49,]        61
## [50,]        62
## [51,]        64
## [52,]        65
## [53,]        66
## [54,]        67
## [55,]        68
## [56,]        69
## [57,]        71
## [58,]        72
## [59,]        74
## [60,]        75
## [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 
##  29.6430209  -0.2073439  -0.1788465   0.4151304  -0.1094680
summary(m1)
## 
## Call:
## lm(formula = MPG ~ ., data = train)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.5636 -3.0325 -0.3562  2.1273 14.3246 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 29.64302   16.70098   1.775   0.0810 .  
## HP          -0.20734    0.04324  -4.795 1.11e-05 ***
## VOL         -0.17885    0.65743  -0.272   0.7865    
## SP           0.41513    0.17645   2.353   0.0219 *  
## WT          -0.10947    1.95909  -0.056   0.9556    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.611 on 60 degrees of freedom
## Multiple R-squared:  0.7567, Adjusted R-squared:  0.7404 
## F-statistic: 46.64 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.4732  -4.7976   0.1821   5.4507  17.3269 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  54.1234     4.6333  11.681  < 2e-16 ***
## VOL          -0.1994     0.0459  -4.345 5.17e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.001 on 63 degrees of freedom
## Multiple R-squared:  0.2306, Adjusted R-squared:  0.2184 
## F-statistic: 18.88 on 1 and 63 DF,  p-value: 5.169e-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.5381  -4.7742   0.2513   5.2685  17.1143 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  53.5477     4.5431  11.787  < 2e-16 ***
## WT           -0.5897     0.1369  -4.306 5.92e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.018 on 63 degrees of freedom
## Multiple R-squared:  0.2274, Adjusted R-squared:  0.2151 
## F-statistic: 18.54 on 1 and 63 DF,  p-value: 5.922e-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.9579  -4.9849  -0.0751   5.3210  18.1646 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  55.6837     5.2465  10.614 1.42e-15 ***
## VOL          -0.9283     1.1314  -0.820    0.415    
## WT            2.1718     3.3687   0.645    0.521    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.038 on 62 degrees of freedom
## Multiple R-squared:  0.2357, Adjusted R-squared:  0.211 
## F-statistic:  9.56 on 2 and 62 DF,  p-value: 0.0002406
# 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   0.043641 -0.069513  0.407022 -1.91e-02 -0.412769  0.64405 0.751
## 2   0.159944  0.054096 -0.235953 -1.08e-01  0.233456  0.41894 0.888
## 4  -0.049196 -0.089031 -0.136315  7.57e-02  0.134702  0.20868 1.123
## 5   0.102858  0.017165  0.216214 -8.35e-02 -0.219065  0.44172 0.862
## 6  -0.035886 -0.070263 -0.105375  5.88e-02  0.103614  0.16773 1.133
## 7   0.130729  0.033950 -0.112154 -8.89e-02  0.109597  0.35942 0.880
## 9  -0.132037 -0.085103  0.077234  1.01e-01 -0.072082 -0.20146 1.279
## 10 -0.030324 -0.041236 -0.005804  3.65e-02  0.005255  0.06148 1.120
## 11  0.016423 -0.016442 -0.058861  2.13e-03  0.057229  0.13044 1.083
## 13  0.030335  0.034133  0.013041 -3.35e-02 -0.012882 -0.04273 1.193
## 15  0.065626  0.019406 -0.075291 -4.21e-02  0.073392  0.17757 1.060
## 17 -0.030481 -0.039225  0.042246  3.35e-02 -0.042983  0.07022 1.139
## 18  0.114515  0.277069  0.109953 -2.52e-01 -0.082232 -0.78312 0.822
## 19 -0.019326 -0.031359 -0.009096  2.62e-02  0.008393  0.05680 1.117
## 21  0.011718  0.012895 -0.008037 -1.21e-02  0.008095 -0.01751 1.141
## 22 -0.006748 -0.027583  0.155318 -9.41e-04 -0.153052  0.25419 1.003
## 23 -0.003249 -0.003289  0.003981  3.13e-03 -0.003988  0.00525 1.206
## 24  0.001156 -0.007731 -0.030797  4.25e-03  0.030619  0.04670 1.129
## 25  0.064985  0.073228 -0.082254 -6.83e-02  0.083670 -0.12201 1.145
## 26 -0.110803  0.036874 -0.001870 -4.38e-03  0.027102 -0.69656 0.834
## 27 -0.165332 -0.158029  0.164687  1.51e-01 -0.162564  0.23850 1.194
## 28  0.006640  0.008542  0.007946 -8.05e-03 -0.007909 -0.01533 1.145
## 29  0.391567  0.321425 -0.212956 -3.72e-01  0.216315  0.48521 1.070
## 30  0.010096  0.011513  0.012788 -1.14e-02 -0.012921 -0.02300 1.149
## 32  0.031262  0.018457 -0.013510 -2.72e-02  0.013883  0.07857 1.091
## 33  0.031577  0.032579 -0.057235 -3.03e-02  0.057503 -0.07130 1.157
## 34 -0.037171 -0.040968 -0.052758  4.02e-02  0.053859  0.09412 1.140
## 35  0.011083  0.004547  0.097224 -1.53e-02 -0.096933  0.12458 1.141
## 36 -0.000938 -0.001820  0.006337  9.82e-04 -0.006354  0.00999 1.123
## 38 -0.020422 -0.000347 -0.108480  1.10e-02  0.111437 -0.18941 1.036
## 39 -0.093759 -0.053169  0.218665  5.97e-02 -0.215933 -0.26609 1.072
## 40  0.175513  0.176923 -0.042317 -1.88e-01  0.045024 -0.24548 1.013
## 41  0.003812  0.001112 -0.019743 -3.67e-03  0.020628  0.04622 1.115
## 42 -0.000438 -0.000250  0.000817  3.70e-04 -0.000838 -0.00181 1.116
## 43 -0.044258 -0.020911  0.121476  2.58e-02 -0.120416 -0.15864 1.084
## 44 -0.033764 -0.020657 -0.145150  3.29e-02  0.146922 -0.19325 1.109
## 45 -0.001225 -0.000770 -0.013775  1.97e-03  0.013711 -0.01769 1.149
## 46 -0.010360 -0.003520  0.018069  6.64e-03 -0.018121 -0.05154 1.097
## 47 -0.002851 -0.003133  0.002108  2.39e-03 -0.001854  0.01420 1.112
## 48 -0.003016 -0.001449  0.002781  2.50e-03 -0.002897 -0.01476 1.108
## 51 -0.085770 -0.081095  0.024176  8.43e-02 -0.025025 -0.13085 1.062
## 52 -0.103342 -0.093969  0.100159  9.62e-02 -0.101077 -0.16432 1.078
## 54  0.171132  0.142275  0.110879 -1.71e-01 -0.112661 -0.26680 1.195
## 55  0.048097  0.036056  0.002394 -4.44e-02 -0.003366 -0.07562 1.131
## 56  0.015978  0.010452 -0.022018 -1.14e-02  0.021152 -0.03792 1.153
## 57 -0.255657 -0.227176  0.029699  2.46e-01 -0.029162 -0.28930 1.062
## 59 -0.204693 -0.185122 -0.081266  2.03e-01  0.081650 -0.28472 1.018
## 60 -0.038185 -0.041704 -0.063019  5.03e-02  0.059973 -0.14674 1.081
## 61  0.025578  0.017373  0.077517 -2.66e-02 -0.078983 -0.12136 1.118
## 62 -0.130160 -0.150254 -0.120059  1.55e-01  0.115449 -0.25902 1.092
## 64 -0.043459 -0.059998  0.048115  5.39e-02 -0.051828 -0.13634 1.113
## 65 -0.030981 -0.044813  0.059554  3.72e-02 -0.062251 -0.11440 1.133
## 66  0.147464  0.137955  0.069769 -1.29e-01 -0.076883  0.27397 1.243
## 67 -0.033113 -0.050918  0.126663  3.50e-02 -0.129226 -0.17595 1.136
## 68  0.008927  0.001167 -0.017926 -3.99e-03  0.017085 -0.03422 1.168
## 69  0.008896 -0.005099 -0.009598 -1.26e-03  0.007993 -0.06027 1.133
## 71  0.552529  0.384804 -0.271075 -6.15e-01  0.305532 -1.46402 0.880
## 72 -0.019803 -0.006860  0.044213  1.04e-02 -0.042743  0.06360 1.242
## 74  0.020759  0.039497 -0.005235 -3.68e-02  0.009481  0.11399 1.286
## 75 -0.198629 -0.235529  0.050154  2.29e-01 -0.058720 -0.32646 1.107
## 77  0.103902  0.462358 -0.347098  6.61e-06  0.295485  2.52470 0.428
## 78 -0.005679  0.016498 -0.009584 -1.22e-03  0.010666  0.07945 1.190
## 79  0.262522  0.347413  0.128376 -2.34e-01 -0.147226  0.83737 1.099
## 80 -0.313594 -0.073315 -0.181897  2.53e-01  0.190966  0.89338 1.045
## 81 -0.350321 -0.433345 -0.031047  3.87e-01  0.026850 -0.49233 1.311
##      cook.d    hat inf
## 1  7.72e-02 0.0704    
## 2  3.39e-02 0.0533    
## 4  8.78e-03 0.0746    
## 5  3.75e-02 0.0530    
## 6  5.69e-03 0.0698    
## 7  2.50e-02 0.0405    
## 9  8.23e-03 0.1641   *
## 10 7.68e-04 0.0369    
## 11 3.43e-03 0.0349    
## 13 3.71e-04 0.0894    
## 15 6.33e-03 0.0389    
## 17 1.00e-03 0.0524    
## 18 1.15e-01 0.1114    
## 19 6.55e-04 0.0335    
## 21 6.23e-05 0.0474    
## 22 1.28e-02 0.0418    
## 23 5.60e-06 0.0984    
## 24 4.43e-04 0.0411    
## 25 3.02e-03 0.0668    
## 26 9.17e-02 0.0974    
## 27 1.15e-02 0.1202    
## 28 4.78e-05 0.0508    
## 29 4.65e-02 0.1199    
## 30 1.08e-04 0.0543    
## 32 1.25e-03 0.0241    
## 33 1.03e-03 0.0657    
## 34 1.80e-03 0.0574    
## 35 3.14e-03 0.0646    
## 36 2.03e-05 0.0320    
## 38 7.18e-03 0.0347    
## 39 1.42e-02 0.0665    
## 40 1.20e-02 0.0423    
## 41 4.34e-04 0.0305    
## 42 6.66e-07 0.0255    
## 43 5.07e-03 0.0430    
## 44 7.53e-03 0.0638    
## 45 6.36e-05 0.0536    
## 46 5.39e-04 0.0194    
## 47 4.10e-05 0.0227    
## 48 4.43e-05 0.0189    
## 51 3.45e-03 0.0271    
## 52 5.43e-03 0.0421    
## 54 1.44e-02 0.1266    
## 55 1.16e-03 0.0476    
## 56 2.92e-04 0.0585    
## 57 1.67e-02 0.0689    
## 59 1.61e-02 0.0531    
## 60 4.34e-03 0.0383    
## 61 2.98e-03 0.0502    
## 62 1.35e-02 0.0728    
## 64 3.76e-03 0.0507    
## 65 2.65e-03 0.0574    
## 66 1.52e-02 0.1549    
## 67 6.26e-03 0.0738    
## 68 2.38e-04 0.0702    
## 69 7.38e-04 0.0463    
## 71 3.94e-01 0.2545   *
## 72 8.22e-04 0.1261    
## 74 2.64e-03 0.1594   *
## 75 2.13e-02 0.0964    
## 77 1.01e+00 0.2748   *
## 78 1.28e-03 0.0910    
## 79 1.36e-01 0.2075    
## 80 1.54e-01 0.2000   *
## 81 4.86e-02 0.2262   *
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
## 71 -2.505789 0.2544835 0.3940027
## 77  4.101218 0.2748165 1.0088307
# 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 
## -9.5636 -3.0325 -0.3562  2.1273 14.3246 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 29.64302   16.70098   1.775   0.0810 .  
## VOL         -0.17885    0.65743  -0.272   0.7865    
## SP           0.41513    0.17645   2.353   0.0219 *  
## HP          -0.20734    0.04324  -4.795 1.11e-05 ***
## WT          -0.10947    1.95909  -0.056   0.9556    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.611 on 60 degrees of freedom
## Multiple R-squared:  0.7567, Adjusted R-squared:  0.7404 
## F-statistic: 46.64 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 
## -9.5636 -3.0325 -0.3562  2.1273 14.3246 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 29.64302   16.70098   1.775   0.0810 .  
## VOL         -0.17885    0.65743  -0.272   0.7865    
## SP           0.41513    0.17645   2.353   0.0219 *  
## HP          -0.20734    0.04324  -4.795 1.11e-05 ***
## WT          -0.10947    1.95909  -0.056   0.9556    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.611 on 60 degrees of freedom
## Multiple R-squared:  0.7567, Adjusted R-squared:  0.7404 
## F-statistic: 46.64 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 
##  19.73908 617.79515  19.64267 618.80888
## 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 
## -9.6808 -2.8470 -0.4567  1.8888 14.4150 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 28.62774   16.15461   1.772   0.0814 .  
## WT          -0.64198    0.07881  -8.145 2.47e-11 ***
## SP           0.42198    0.17332   2.435   0.0178 *  
## HP          -0.20917    0.04239  -4.935 6.52e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.576 on 61 degrees of freedom
## Multiple R-squared:  0.7564, Adjusted R-squared:  0.7444 
## F-statistic: 63.12 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 
## -9.5365 -3.0712 -0.3303  2.1783 14.3088 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 29.85011   16.15094   1.848   0.0694 .  
## VOL         -0.21555    0.02643  -8.155 2.38e-11 ***
## SP           0.41367    0.17309   2.390   0.0200 *  
## HP          -0.20696    0.04233  -4.889 7.70e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.573 on 61 degrees of freedom
## Multiple R-squared:  0.7566, Adjusted R-squared:  0.7447 
## F-statistic: 63.22 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)

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