Question

Heavier cars seem like they would use more gas.

My question: Does a car’s weight affect its miles per gallon (mpg)?

I used the mtcars dataset that comes with R. It has 32 cars from a 1974 Motor Trend magazine.

Variables I used:

  • wt = weight (in 1000 lbs)
  • mpg = miles per gallon
  • hp = horsepower

Looking at the Data

The heavier cars have lower mpg. It looks kind of like a straight line going down so linear regression should work.

Correlation

Correlation tells how strong the linear relationship is between x and y.

\[r = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum (x_i - \bar{x})^2 \sum (y_i - \bar{y})^2}}\]

r is always between -1 and 1. Close to -1 means a strong negative relationship.

For this data r = -0.87, so it is a strong negative relationship.

Linear Regression Model

The model is

\[y = \beta_0 + \beta_1 x + \varepsilon\]

The least squares estimates are

\[\hat{\beta}_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \qquad \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x}\]

To see if weight matters I tested \(H_0: \beta_1 = 0\) vs \(H_a: \beta_1 \neq 0\)

R Code

model <- lm(mpg ~ wt, data = mtcars)
coef(model)
## (Intercept)          wt 
##   37.285126   -5.344472
confint(model)
##                 2.5 %    97.5 %
## (Intercept) 33.450500 41.119753
## wt          -6.486308 -4.202635
cor(mtcars$wt, mtcars$mpg)
## [1] -0.8676594

Results

  • Equation: mpg = 37.29 - 5.34(wt)
  • Slope = -5.34, so every 1000 lbs lowers mpg by about 5.3
  • p-value = 1.29e-10 which is way less than 0.05, so we reject \(H_0\)
  • 95% CI for slope: (-6.49, -4.20)
  • \(R^2\) = 0.75, so weight explains about 75% of the variation in mpg

Regression Line

The line fits the points pretty well. The gray area is the confidence band for the line.

3D Plot with Horsepower

You can rotate this. Cars with high weight and high horsepower have the lowest mpg.

Conclusion

  • Weight and mpg have a strong negative relationship (r = -0.87)
  • Each extra 1000 lbs lowers mpg by about 5.3
  • The result is significant (p < 0.05)
  • Horsepower also seems to matter, so weight is not the only thing

Limitations: only 32 cars and they are all from 1974, so newer cars might be different. Also this only shows a relationship, not that weight causes lower mpg.