SlideShare a Scribd company logo
1 of 5
Download to read offline
Motor Trend Analysis: Transmission effect on MPG
Slaw7
Data overview
Some basic exploratory data analysis of the mtcars data set.
We will look at a plot of Aautomatic/Manual transmission versus Miles Per Gallon.
library(ggplot2)
mpg_range <- range(0, mtcars$mpg)
par(mar=c(5.1,4.1,0.1,0.1))
plot(mpg~factor(am), data=mtcars,
xlab = "Transmission Type",
ylab="Miles Per Gallon (MPG)",
axes=FALSE, ann=FALSE)
axis(1, at=1:2, lab=c("Automatic","Manual"))
axis(2, las=1, at=5*0:mpg_range[2]); box()
It looks as though Munual Transmission cars have a better mpg than Automatic Transmission cars. However, we would like
to know more about other contributing factors.
cor(mtcars)[,c(1,9)]
## mpg am
## mpg 1.0000000 0.59983243
## cyl -0.8521620 -0.52260705
## disp -0.8475514 -0.59122704
## hp -0.7761684 -0.24320426
## drat 0.6811719 0.71271113
## wt -0.8676594 -0.69249526
## qsec 0.4186840 -0.22986086
## vs 0.6640389 0.16834512
## am 0.5998324 1.00000000
## gear 0.4802848 0.79405876
## carb -0.5509251 0.05753435
When looking at the correlation between the
variables of this data set, we see that four
variables have a correlation larger than 0.5
(in absolute value) with both “mpg” and
“am”. Those are: number of cylinders, dis-
placement, rear axle ratio (drat) and weight.
The appendix contains a visual of the rela-
tionships between these four variables with
both “mpg” and “am”.
Regression Models
A simple non-adjusted model. (Model 1)
Our first model will simply be based on the relationship between MPG and Type of Transmission without taking into
consideration any other variables.
fit1 <- lm(mpg~factor(am), data=mtcars)
summary(fit1)$coef[2,]
## Estimate Std. Error t value Pr(>|t|)
## 7.2449392713 1.7644216316 4.1061269831 0.0002850207
We estimate, not taking any other variables
into consideration, a manual transmission
will increase MPG by 7.24 mpg.
1
summary(fit1)$r.squared
## [1] 0.3597989
The R-squared value tells us that type of
Transmission alone is only accounting for
35.98% of the variance in MPG.
An adjusted model. (Model 2)
Next we will consider the effects of taking the four variables we identified above into account.
fit2 <- lm(mpg~factor(am)+factor(cyl)+disp+drat+wt,data=mtcars)
summary(fit2)$coef
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 34.796706680 6.70238133 5.1916931 2.271364e-05
## factor(am)1 0.261365828 1.53969659 0.1697515 8.665717e-01
## factor(cyl)6 -4.374626281 1.58014542 -2.7684960 1.045306e-02
## factor(cyl)8 -6.407637752 2.75347514 -2.3271094 2.835383e-02
## disp 0.001425009 0.01407923 0.1012136 9.201883e-01
## drat -0.255596739 1.56599820 -0.1632165 8.716602e-01
## wt -3.251684420 1.27325003 -2.5538459 1.713143e-02
Our adjusted estimate is that a manual trans-
mission will only increase MPG by 0.26 mpg.
But with a large p-value, we cannot conclude
that the Type of Transmission actually has
an effect on the mpg.
summary(fit2)$r.squared
## [1] 0.8377735
The R-squared value tells us that the five
variables used in our model, together account
for 83.78% of the variance in MPG.
Comparing the two models.
We will perform an anova test to compare the above models
anova(fit1,fit2)
## Analysis of Variance Table
##
## Model 1: mpg ~ factor(am)
## Model 2: mpg ~ factor(am) + factor(cyl) + disp + drat + wt
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 30 720.90
## 2 25 182.67 5 538.22 14.732 9.059e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
We conclude from the low p-value that we can reject the null hypothesis, and that the additional variables in the second
model are necessary to improve the prediction mpg.
Further analysis using a residual plot of the multivariate model is given in the Appendix section below.
Executive Summary
In this report we developed two models using the mtcars dataset, and used the results to answer the following questions.
Is an automatic or manual transmission better for MPG?
There is evidence to suggest that a manual transmission is better for MPG than an automatic, however, the difference between
the two may be minimal.
Quantify the MPG difference between automatic and manual transmissions.
Taking into account variables such as number of cylinders, displacement, rear axle ratio, and weight, the difference between
automatic and manual transmissions is estimated to be 0.26 mpg.
2
Appendix
par(mfrow=c(1,2))
plot(mpg~factor(cyl), data=mtcars, xlab="Number of Cylinders", ylab="Miles per Gallon (MPG)")
plot(factor(cyl)~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Number of Cyli
par(mfrow=c(1,2))
plot(mpg~disp, data=mtcars, xlab="Displacement", ylab="Miles per Gallon (MPG)")
plot(disp~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Displacement")
3
par(mfrow=c(1,2))
plot(mpg~drat, data=mtcars, xlab="Rear Axle Ratio", ylab="Miles per Gallon (MPG)")
plot(drat~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Rear Axle Ratio")
par(mfrow=c(1,2))
plot(mpg~wt, data=mtcars, xlab="Weight", ylab="Miles per Gallon (MPG)")
plot(wt~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Weight")
4
par(mfrow = c(2, 2))
plot(fit2)
5

More Related Content

Similar to CarProject

International Journal of Computational Engineering Research (IJCER)
International Journal of Computational Engineering Research (IJCER) International Journal of Computational Engineering Research (IJCER)
International Journal of Computational Engineering Research (IJCER) ijceronline
 
Lab practice session.pptx
Lab practice session.pptxLab practice session.pptx
Lab practice session.pptxakashayosha
 
Linear models
Linear modelsLinear models
Linear modelsFAO
 
Data Visualization With R: Introduction
Data Visualization With R: IntroductionData Visualization With R: Introduction
Data Visualization With R: IntroductionRsquared Academy
 
Auto MPG Regression Analysis
Auto MPG Regression AnalysisAuto MPG Regression Analysis
Auto MPG Regression AnalysisAnirudh Srinath.V
 
76201979
7620197976201979
76201979IJRAT
 
Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...
Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...
Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...IRJET Journal
 
Applied Regression Analysis using R
Applied Regression Analysis using RApplied Regression Analysis using R
Applied Regression Analysis using RTarek Dib
 
A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...
A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...
A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...IRJET Journal
 
library(tidyr) and library(ggplot2)
library(tidyr)  and library(ggplot2)library(tidyr)  and library(ggplot2)
library(tidyr) and library(ggplot2)Dr. Volkan OBAN
 
Improving time to-collision estimation by IMM based Kalman filter
Improving time to-collision estimation by IMM based Kalman filterImproving time to-collision estimation by IMM based Kalman filter
Improving time to-collision estimation by IMM based Kalman filterYixin Chen
 
On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...
On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...
On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...IRJET Journal
 

Similar to CarProject (20)

posterCP2015(1)
posterCP2015(1)posterCP2015(1)
posterCP2015(1)
 
International Journal of Computational Engineering Research (IJCER)
International Journal of Computational Engineering Research (IJCER) International Journal of Computational Engineering Research (IJCER)
International Journal of Computational Engineering Research (IJCER)
 
Automobile design
Automobile designAutomobile design
Automobile design
 
Lab practice session.pptx
Lab practice session.pptxLab practice session.pptx
Lab practice session.pptx
 
AUTO MPG Regression Analysis
AUTO MPG Regression AnalysisAUTO MPG Regression Analysis
AUTO MPG Regression Analysis
 
Linear models
Linear modelsLinear models
Linear models
 
Data Visualization With R: Introduction
Data Visualization With R: IntroductionData Visualization With R: Introduction
Data Visualization With R: Introduction
 
Session 38 Xiaoliang Ma
Session 38 Xiaoliang MaSession 38 Xiaoliang Ma
Session 38 Xiaoliang Ma
 
Auto MPG Regression Analysis
Auto MPG Regression AnalysisAuto MPG Regression Analysis
Auto MPG Regression Analysis
 
76201979
7620197976201979
76201979
 
Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...
Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...
Adaptive Cruise Control System for Vehicle Using Model Predictive Control Alg...
 
Applied Regression Analysis using R
Applied Regression Analysis using RApplied Regression Analysis using R
Applied Regression Analysis using R
 
chapter3
chapter3chapter3
chapter3
 
A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...
A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...
A Novel 4WD Permanent Magnet Synchronous Motor for an Electrical Vehicle Cont...
 
Autonomous Cars
Autonomous CarsAutonomous Cars
Autonomous Cars
 
library(tidyr) and library(ggplot2)
library(tidyr)  and library(ggplot2)library(tidyr)  and library(ggplot2)
library(tidyr) and library(ggplot2)
 
Multiple Regression
Multiple RegressionMultiple Regression
Multiple Regression
 
12. Linear models
12. Linear models12. Linear models
12. Linear models
 
Improving time to-collision estimation by IMM based Kalman filter
Improving time to-collision estimation by IMM based Kalman filterImproving time to-collision estimation by IMM based Kalman filter
Improving time to-collision estimation by IMM based Kalman filter
 
On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...
On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...
On the Selection of Optimum Blend of WPO – Combinatorial Mathematics Based Ap...
 

CarProject

  • 1. Motor Trend Analysis: Transmission effect on MPG Slaw7 Data overview Some basic exploratory data analysis of the mtcars data set. We will look at a plot of Aautomatic/Manual transmission versus Miles Per Gallon. library(ggplot2) mpg_range <- range(0, mtcars$mpg) par(mar=c(5.1,4.1,0.1,0.1)) plot(mpg~factor(am), data=mtcars, xlab = "Transmission Type", ylab="Miles Per Gallon (MPG)", axes=FALSE, ann=FALSE) axis(1, at=1:2, lab=c("Automatic","Manual")) axis(2, las=1, at=5*0:mpg_range[2]); box() It looks as though Munual Transmission cars have a better mpg than Automatic Transmission cars. However, we would like to know more about other contributing factors. cor(mtcars)[,c(1,9)] ## mpg am ## mpg 1.0000000 0.59983243 ## cyl -0.8521620 -0.52260705 ## disp -0.8475514 -0.59122704 ## hp -0.7761684 -0.24320426 ## drat 0.6811719 0.71271113 ## wt -0.8676594 -0.69249526 ## qsec 0.4186840 -0.22986086 ## vs 0.6640389 0.16834512 ## am 0.5998324 1.00000000 ## gear 0.4802848 0.79405876 ## carb -0.5509251 0.05753435 When looking at the correlation between the variables of this data set, we see that four variables have a correlation larger than 0.5 (in absolute value) with both “mpg” and “am”. Those are: number of cylinders, dis- placement, rear axle ratio (drat) and weight. The appendix contains a visual of the rela- tionships between these four variables with both “mpg” and “am”. Regression Models A simple non-adjusted model. (Model 1) Our first model will simply be based on the relationship between MPG and Type of Transmission without taking into consideration any other variables. fit1 <- lm(mpg~factor(am), data=mtcars) summary(fit1)$coef[2,] ## Estimate Std. Error t value Pr(>|t|) ## 7.2449392713 1.7644216316 4.1061269831 0.0002850207 We estimate, not taking any other variables into consideration, a manual transmission will increase MPG by 7.24 mpg. 1
  • 2. summary(fit1)$r.squared ## [1] 0.3597989 The R-squared value tells us that type of Transmission alone is only accounting for 35.98% of the variance in MPG. An adjusted model. (Model 2) Next we will consider the effects of taking the four variables we identified above into account. fit2 <- lm(mpg~factor(am)+factor(cyl)+disp+drat+wt,data=mtcars) summary(fit2)$coef ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 34.796706680 6.70238133 5.1916931 2.271364e-05 ## factor(am)1 0.261365828 1.53969659 0.1697515 8.665717e-01 ## factor(cyl)6 -4.374626281 1.58014542 -2.7684960 1.045306e-02 ## factor(cyl)8 -6.407637752 2.75347514 -2.3271094 2.835383e-02 ## disp 0.001425009 0.01407923 0.1012136 9.201883e-01 ## drat -0.255596739 1.56599820 -0.1632165 8.716602e-01 ## wt -3.251684420 1.27325003 -2.5538459 1.713143e-02 Our adjusted estimate is that a manual trans- mission will only increase MPG by 0.26 mpg. But with a large p-value, we cannot conclude that the Type of Transmission actually has an effect on the mpg. summary(fit2)$r.squared ## [1] 0.8377735 The R-squared value tells us that the five variables used in our model, together account for 83.78% of the variance in MPG. Comparing the two models. We will perform an anova test to compare the above models anova(fit1,fit2) ## Analysis of Variance Table ## ## Model 1: mpg ~ factor(am) ## Model 2: mpg ~ factor(am) + factor(cyl) + disp + drat + wt ## Res.Df RSS Df Sum of Sq F Pr(>F) ## 1 30 720.90 ## 2 25 182.67 5 538.22 14.732 9.059e-07 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 We conclude from the low p-value that we can reject the null hypothesis, and that the additional variables in the second model are necessary to improve the prediction mpg. Further analysis using a residual plot of the multivariate model is given in the Appendix section below. Executive Summary In this report we developed two models using the mtcars dataset, and used the results to answer the following questions. Is an automatic or manual transmission better for MPG? There is evidence to suggest that a manual transmission is better for MPG than an automatic, however, the difference between the two may be minimal. Quantify the MPG difference between automatic and manual transmissions. Taking into account variables such as number of cylinders, displacement, rear axle ratio, and weight, the difference between automatic and manual transmissions is estimated to be 0.26 mpg. 2
  • 3. Appendix par(mfrow=c(1,2)) plot(mpg~factor(cyl), data=mtcars, xlab="Number of Cylinders", ylab="Miles per Gallon (MPG)") plot(factor(cyl)~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Number of Cyli par(mfrow=c(1,2)) plot(mpg~disp, data=mtcars, xlab="Displacement", ylab="Miles per Gallon (MPG)") plot(disp~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Displacement") 3
  • 4. par(mfrow=c(1,2)) plot(mpg~drat, data=mtcars, xlab="Rear Axle Ratio", ylab="Miles per Gallon (MPG)") plot(drat~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Rear Axle Ratio") par(mfrow=c(1,2)) plot(mpg~wt, data=mtcars, xlab="Weight", ylab="Miles per Gallon (MPG)") plot(wt~factor(am), data=mtcars, xlab="Transmission (0 = automatic, 1 = manual)", ylab="Weight") 4
  • 5. par(mfrow = c(2, 2)) plot(fit2) 5