1. The Question:

“Do engine displacement (Engine Scale), have affects on car’s MPG value?”

Miles per Gallon, or MPG, is a measurement of how many miles a car can run with one gallon of gas. This measurement is primary use to see how efficient is a car and give the user a better look of how much money they can save on gas depend on this number.

While the MPG measurement can depend on many different values, such as weight, engine type, type of car, how many passenger or cargo that the car is having, one of the biggest factor that can contribute to the change in MPG of a car is the engine displacement. Engine displacement, in a simple term, is how big the engine is equipped for that car. We believe that bigger engine will produce more power for the car, but at the same time, cost more fuel to run in the same distance.

Therefore, the goal that we are trying to achieve today is to learn and use statistics, as well as numeric data from the mpg dataset to predict the mpg in car based on its engine displacement.

2. Why statistics?

The reason why I would like to use statistics is because it can give me a better and more precise look at the relation between the 2 values (mpg and engine displacement).

Moreover, using statistics might help us in the future to predict the value of the mpg based on the car’s engine scale, using existing data.

3. Statistical idea:

The idea behind the math for this project is to use point estimate. Which is a technique by calculating the mean, or the average, of a range of data that we want to investigate.

  1. We will take the point average of the MPG of all cars in the data set. This is the standard “expected” MPG in any cars you pick.

  2. We will label the car to 2 type, large engine and small engine.

  3. Next, we will calculate the average MPG in each category, and compare it with the average MPG to say if the scale of engine can affect the MPG value in a car.

Then, we can use this mean of the type of data, to later predict the result based on estimating the point in the range of the mean that we computed before.

4. Mean

\[\bar{x} = \frac{x_1 + x_2 + \cdots + x_n}{n}\]

In simple term, this is just add up all the number of one type together, then divide them by how many values we have. Therefore, we have a number that is roughly the average value of all of them.

For the mpg of the cars : \(\bar{x} =\) 23.44.

5. Precision of The Math

The standard error tells us how much \(\bar{x}\) might change from sample to sample:

\[SE = \frac{s}{\sqrt{n}} = \frac{5.95}{\sqrt{234}} = 0.39\]

Here \(s\), is the standard deviation value, or how spread out the data is in the dataset.

The more data we have, which \(n\) makes the standard error smaller, the better and more precise our calculation and prediction might be.

The number 0.39 also means that if we took another sample (dataset) of around this number, the average value (MPG), will tend to varies from 0.39 MPG.

6. R Code

x <- mpg$hwy
mean(x)
## [1] 23.44017
sd(x)
## [1] 5.954643
mpg$size <- ifelse(mpg$displ <= 3, "Small", "Large")
aggregate(hwy ~ size, data = mpg, FUN = mean)
##    size      hwy
## 1 Large 19.54762
## 2 Small 27.98148

Mean: 23.44, this means that for all the cars in the dataset, the average MPG value of that car will be 23.44. However, this number is not accurate for all cars, because there are many factor that contribute to the change of MPG when using a car.

Standard Deviation: 5.95

Large: 19.547, this is all the car that have the value of their engine displacement of more than 3L.

Small: 27.981, this is all the car that have the value of their engine displacement of 3 or less.

Data Plot 1

Data Plot 2: Small Engines

Data Plot 3: Large Engines

Interactive Plot

  library(plotly)
  plot_ly(mpg, x = ~hwy, color = ~size,
        colors = c("orange", "green"), type = "histogram",
        alpha = 0.7, nbinsx = 20, width = 700, height = 350) %>%
  layout(barmode = "overlay",
         xaxis = list(title = "Highway mpg"),
         yaxis = list(title = "Number of cars"))

What Did We Learn?

The first thing that we can confirm from our analysis is that the engine size do have a relation with the MPG in a car. The proof is that the MPG of car with labeled as Large is 19.5, and Small is 28. Which indicated that with the same one gallon of gas, any cars with label Large can go less than a car with label Small.

Moreover, the graph also indicated that for car with small engine, most of the MPG is in the range of 30. However, the MPG for car with large engine does not average around this scale. In fact, there are 0 cars with large engine can exceed the 30 MPG limit.

Therefore, we can answer our question, that the engine displacement, or the engine size, do have huge impact and relation to the MPG value of the car. The trend we observed is that the larger the engine, the less miles the car can covers in one gallon.