regression models- others

2
Effect of Transmission Type on a Car’s Mileage Shridhara Aithal Friday, July 24, 2015 Executive Summary This report is to identify the effect of transmission type (automatic vs. manual) on a car’s mileage. We perform some analysis on mtcars dataset to determine whether manual transmission is better than automatic and quantify the difference if any. Our analysis shows that cars with manual transmission have a better mileage than the cars with automatic transmission. Holding all other variables constant, manual transmission give an average of 7.25mpg more than automatic transmission. Analysis We first load mtcars dataset and do a bit of preprocessing and basic analysis to understand the data. library(dplyr) library(ggplot2) data(mtcars) mtcars$am <- factor(mtcars$am, labels = c("Automatic", "Manual")) c <- group_by(mtcars, am) summarize(c, mean(mpg)) ## Source: local data frame [2 x 2] ## ## am mean(mpg) ## 1 Automatic 17.14737 ## 2 Manual 24.39231 c <- group_by(mtcars, cyl, am) summarize(c, mean(mpg)) ## Source: local data frame [6 x 3] ## Groups: cyl ## ## cyl am mean(mpg) ## 1 4 Automatic 22.90000 ## 2 4 Manual 28.07500 ## 3 6 Automatic 19.12500 ## 4 6 Manual 20.56667 ## 5 8 Automatic 15.05000 ## 6 8 Manual 15.40000 From the summary, we see that on an average, manual transmission has better mpg than automatic whether we consider number of cylinders or not. We now fit a model and see what the model predicts. 1

Upload: pareen5

Post on 25-Jan-2016

6 views

Category:

Documents


1 download

DESCRIPTION

Regression Models- Others

TRANSCRIPT

Page 1: Regression Models- Others

Effect of Transmission Type on a Car’s MileageShridhara Aithal

Friday, July 24, 2015

Executive Summary

This report is to identify the effect of transmission type (automatic vs. manual) on a car’s mileage. Weperform some analysis on mtcars dataset to determine whether manual transmission is better than automaticand quantify the difference if any.

Our analysis shows that cars with manual transmission have a better mileage than the cars with automatictransmission. Holding all other variables constant, manual transmission give an average of 7.25mpg morethan automatic transmission.

Analysis

We first load mtcars dataset and do a bit of preprocessing and basic analysis to understand the data.

library(dplyr)library(ggplot2)

data(mtcars)mtcars$am <- factor(mtcars$am, labels = c("Automatic", "Manual"))c <- group_by(mtcars, am)summarize(c, mean(mpg))

## Source: local data frame [2 x 2]#### am mean(mpg)## 1 Automatic 17.14737## 2 Manual 24.39231

c <- group_by(mtcars, cyl, am)summarize(c, mean(mpg))

## Source: local data frame [6 x 3]## Groups: cyl#### cyl am mean(mpg)## 1 4 Automatic 22.90000## 2 4 Manual 28.07500## 3 6 Automatic 19.12500## 4 6 Manual 20.56667## 5 8 Automatic 15.05000## 6 8 Manual 15.40000

From the summary, we see that on an average, manual transmission has better mpg than automatic whetherwe consider number of cylinders or not.

We now fit a model and see what the model predicts.

1

Page 2: Regression Models- Others

fit <- lm(mpg ~ am, data = mtcars)summary(fit)$coefficients

## Estimate Std. Error t value Pr(>|t|)## (Intercept) 17.147368 1.124603 15.247492 1.133983e-15## amManual 7.244939 1.764422 4.106127 2.850207e-04

From the coefficients of the model we see that manual transmission has a positive slope (a difference of7.25mpg) in comparison with automatic transmission and the relationship is significant (with a low p-value)

We now plot the residuals to see their characteristics

qplot(mtcars$am, resid(fit)) + geom_boxplot() + ylab("Residuals (mpg)") +xlab("Transmission") + ggtitle("Residuals")

−10

−5

0

5

10

Automatic ManualTransmission

Res

idua

ls (

mpg

)

Residuals

From the plot we see that the residuals for manual transmission have a greater variation than that ofautomatic transmission.

2