Executive Summary

The relationship between fuel consumption (MPG) and cars transmission was studied in this report. Regression models were used to compare fuel consumption of automatic and manual cars, and here is the summary of the results:
  • Mean and median fuel consumption of manual transmission demonstrated better fuel efficiency, higher mileage per gallon, than automatic transmission.
  • t.test showed at 99% confidence level, manual transmission has better fuel efficiency than automatic transmission.
  • Single variable linear regression model shows that manual tranmission has 7.245 mpg higher than automatic transmission, and also at multivariate regression model, manual transmission has still better fuel efficiency than automatic with 0.96 mpg higher.

Exploratory Data Analyses

str(mtcars)
## 'data.frame':    32 obs. of  11 variables:
##  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
##  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
##  $ disp: num  160 160 108 258 360 ...
##  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
##  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
##  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
##  $ qsec: num  16.5 17 18.6 19.4 17 ...
##  $ vs  : Factor w/ 2 levels "0","1": 1 1 2 2 1 2 1 2 2 2 ...
##  $ am  : Factor w/ 2 levels "0","1": 2 2 2 1 1 1 1 1 1 1 ...
##  $ gear: Factor w/ 3 levels "3","4","5": 2 2 2 1 1 1 1 2 2 2 ...
##  $ carb: Factor w/ 6 levels "1","2","3","4",..: 4 4 1 1 2 1 4 2 2 4 ...
head(mtcars,3)
##                mpg cyl disp  hp drat    wt  qsec vs am gear carb
## Mazda RX4     21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## Mazda RX4 Wag 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## Datsun 710    22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
plot(mtcars$am, mtcars$mpg)
title("Fuel consumption for Automatic Vs. Manual transmission", xlab = "Transmission Type", ylab = "MPG")
legend ("topright",  legend = c("0=Auto","1=Manual"), cex = 0.6)

group_by(mtcars, mtcars$am)%>%summarise(avgmpg=mean(mpg))
## # A tibble: 2 x 2
##   `mtcars$am` avgmpg
##   <fct>        <dbl>
## 1 0             17.1
## 2 1             24.4
Manual transmission has better mean, median, maximum and minimum values of fuel efficiency.

Significant Difference between Automatic and Manual tranmission

## subset manual and automatic cars
a<-mtcars$mpg[mtcars$am==0]
m<-mtcars$mpg[mtcars$am==1]

#compare the two using t.test
 t.test(a, m, paired = FALSE, conf.level = 0.99)$conf
## [1] -12.769128  -1.720751
## attr(,"conf.level")
## [1] 0.99
There is a clear significant difference in fuel efficiency between automatic and manual transmission. At 99% confidence level, manual tranmission has better fuel efficiency thatn automatic transmisson.

Regression Analysis

fit <- lm(mpg ~ am, data = mtcars)
summary(fit)
## 
## Call:
## lm(formula = mpg ~ am, data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.3923 -3.0923 -0.2974  3.2439  9.5077 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   17.147      1.125  15.247 1.13e-15 ***
## am1            7.245      1.764   4.106 0.000285 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.902 on 30 degrees of freedom
## Multiple R-squared:  0.3598, Adjusted R-squared:  0.3385 
## F-statistic: 16.86 on 1 and 30 DF,  p-value: 0.000285
Single variable linear regression model showed that manual tranmission has 7.245 mpg higher than automatic transmission. Which means manual transmission has better fuel consumption than automatic transmission.
Risdual value (R-squared) is low 0.3598, meaning that this regression model could be improved if more variable is included.
fitAll<- lm(mpg ~ ., data = mtcars)
summary(fitAll)
## 
## Call:
## lm(formula = mpg ~ ., data = mtcars)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.6533 -1.3325 -0.5166  0.7643  4.7284 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) 25.31994   23.88164   1.060   0.3048  
## cyl         -1.02343    1.48131  -0.691   0.4995  
## disp         0.04377    0.03058   1.431   0.1716  
## hp          -0.04881    0.03189  -1.531   0.1454  
## drat         1.82084    2.38101   0.765   0.4556  
## wt          -4.63540    2.52737  -1.834   0.0853 .
## qsec         0.26967    0.92631   0.291   0.7747  
## vs1          1.04908    2.70495   0.388   0.7032  
## am1          0.96265    3.19138   0.302   0.7668  
## gear4        1.75360    3.72534   0.471   0.6442  
## gear5        1.87899    3.65935   0.513   0.6146  
## carb2       -0.93427    2.30934  -0.405   0.6912  
## carb3        3.42169    4.25513   0.804   0.4331  
## carb4       -0.99364    3.84683  -0.258   0.7995  
## carb6        1.94389    5.76983   0.337   0.7406  
## carb8        4.36998    7.75434   0.564   0.5809  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.823 on 16 degrees of freedom
## Multiple R-squared:  0.8867, Adjusted R-squared:  0.7806 
## F-statistic: 8.352 on 15 and 16 DF,  p-value: 6.044e-05
All other variables were included in this regression model. In this multivariate regression model, manual transmission has still better fuel efficiency than automatic with 0.96 mpg higher. Also, this model is better explain the relationship with higher, risdual value (R-squared0.887

Residual plots

par(mfrow = c(2,2))
plot(fitAll)