Inside Look at the Cars’ Horsepower in the Motor Trend Road Tests

Description:

The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).

Format:
A data frame with 32 observations on 11 variables.

[, 1] mpg Miles/(US) gallon
[, 2] cyl Number of cylinders
[, 3] disp Displacement (cu.in.)
[, 4] hp Gross horsepower
[, 5] drat Rear axle ratio
[, 6] wt Weight (1000 lbs)
[, 7] qsec 1/4 mile time
[, 8] vs V/S
[, 9] am Transmission (0 = automatic, 1 = manual)
[,10] gear Number of forward gears
[,11] carb Number of carburetors

Source:
Henderson and Velleman (1981), Building multiple regression models interactively. Biometrics, 37, 391–411.

Location:
http://vincentarelbundock.github.io/Rdatasets/

Data Exploration: Horsepower

# Load mtcars files from Github
mtcars <- read.csv(url("https://raw.githubusercontent.com/dquarshie89/R-Bridge/master/mtcars.csv"),header = TRUE)
head(mtcars)
##                   X  mpg cyl disp  hp drat    wt  qsec vs am gear carb
## 1         Mazda RX4 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
## 2     Mazda RX4 Wag 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
## 3        Datsun 710 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
## 4    Hornet 4 Drive 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
## 5 Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
## 6           Valiant 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
# Get A summary of the horsepower of the cars tested
summary(mtcars$hp)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    52.0    96.5   123.0   146.7   180.0   335.0
# Looking at the summary we see that the minimum hp is 52, the maximum is 335, and the average is 146.7

Data Analysis

Auto vs Manual Transmission: Which provides more horsepower?
We want to see which type of car gives greater horsepower

##Split the cars into 2 groups (auto and manual)
man <- subset(mtcars, am == 1)
auto <- subset(mtcars, am == 0)  

# Get the average horsepower for each group
avg_hp_man <- mean(man$hp)
avg_hp_auto <- mean(auto$hp)
avg_hp_man
## [1] 126.8462
avg_hp_auto
## [1] 160.2632
# We see that auto transmission cars give more horsepower than manual ones, but by how much?
# Use the formula below to see how much more horsepower auto transmission cars have than manual cars
((avg_hp_auto - avg_hp_man)/avg_hp_man)*100
## [1] 26.34452
# We see that auto transmission cars have 26% more horsepower than manual cars

Horsepower and MPG Relationship
We now know that auto transmission gives more horsepower but how does that affect miles per gallon?

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.3.3
ggplot(mtcars, aes(x=hp, y=mpg)) +  ggtitle("Total MPG by HP") + geom_point(shape=1)

ggplot(auto, aes(x=hp, y=mpg)) +  ggtitle("Automatic MPG by HP")   + geom_point(shape=1)

ggplot(man, aes(x=hp, y=mpg))  +  ggtitle("Manual MPG by HP")  + geom_point(shape=1)

# Looking at the 3 scatterplots it can be concluded that for both automatic and manual transmission cars, as  
# the amount of horsepower increases the miles per gallon the car gets will decrease.

Conclusion

Using the data set provided from the Motor Trend test we see that you’ll get more horsepower with a auto transmission car. However opting for a car with higher horsepower will lessen the miles per gallon the car will get.