The question

Do heavier cars tend to travel fewer miles per gallon?

I wanted to see how closely a car’s weight is related to its fuel economy.

I used correlation to measure the relationship and linear regression to fit a line.

Higher MPG means the car travels farther on one US gallon of fuel.

The data

R’s built-in mtcars dataset contains 32 cars from the 1973–1974 model years, reported in the 1974 Motor Trend magazine.

Variable Meaning
wt Vehicle weight, in thousands of pounds
mpg Miles per US gallon
hp Gross horsepower

These are older cars, so the results may not apply to cars today.

Source: R datasets documentation, “Motor Trend Car Road Tests.”

Heavier cars generally have lower MPG

The downward pattern is clear: heavier cars tend to get lower MPG. There are still differences between cars of similar weight.

Mathematics 1: measuring correlation

Correlation measures the strength and direction of a linear relationship:

\[r=\frac{\sum_{i=1}^{n}(x_i-\bar{x})(y_i-\bar{y})} {\sqrt{\sum_{i=1}^{n}(x_i-\bar{x})^2\sum_{i=1}^{n}(y_i-\bar{y})^2}}\]

Here, \(x_i\) is weight and \(y_i\) is MPG for car \(i\).

For these cars, \(r = -0.868\).

This is a strong negative relationship. It does not prove that weight causes the difference.

Mathematics 2: fitting a regression line

The model relates MPG to weight, with an error term:

\[y_i=\beta_0+\beta_1 x_i+\varepsilon_i\]

Least squares chooses the intercept and slope to minimize:

\[\sum_{i=1}^{n}(y_i-\hat{y}_i)^2, \qquad \hat{y}_i=b_0+b_1x_i\]

The fitted equation is:

\[\widehat{\mathrm{MPG}}=37.29-5.34\times\mathrm{weight\;(1,000\;lb)}\]

R code behind the analysis

library(ggplot2)
library(plotly)
cars <- datasets::mtcars
fit <- lm(mpg ~ wt, data = cars)
cor(cars$wt, cars$mpg)
summary(fit)
confint(fit, "wt")
ggplot(cars, aes(wt, mpg)) +
  geom_point(color = "#8C1D40") +
  geom_smooth(method = "lm", se = TRUE)

lm() estimates the line. cor() measures the relationship, and confint() gives a model-based interval for the slope.

The line captures much of the relationship

The slope is -5.34 MPG per 1,000 lb. The gold band is a 95% confidence interval for mean MPG under the model, not a prediction interval for an individual car.

What the fitted model means

  • An additional 1,000 lb is associated with about 5.34 lower MPG in this sample.
  • At 3,000 lb, the line predicts 21.3 MPG.
  • \(R^2 = 0.753\): weight accounts for about 75.3% of the observed variation in MPG around its sample mean.
  • The model-based 95% slope interval is [-6.49, -4.20] MPG per 1,000 lb.

The intercept predicts MPG at zero weight. That is outside the observed data and has no useful physical interpretation here.

Residuals show where the model misses

The line misses some cars by several MPG. The curved pattern suggests a straight line may be too simple.

Interactive view: horsepower adds context

Drag to rotate and hover to see each car. Horsepower varies too, so weight is not the whole story. This plot does not control for horsepower.

Limits of the analysis

  • Association: Engine design and other features may help explain the relationship. This analysis does not isolate the causal effect of weight.
  • Scope: These 32 cars come from 1973–1974. The results should not be applied directly to modern cars or electric vehicles.
  • Model assumptions: Classical confidence intervals assume a linear mean relationship, independent errors, constant error variance, and normally distributed errors for exact small-sample inference.
  • Prediction: Predictions within the observed range are more defensible than extrapolation. A fitted mean does not describe every individual car.

What did we learn?

Heavier cars tend to have lower MPG in this dataset.

The correlation is -0.868, and the regression estimates about 5.34 fewer MPG per additional 1,000 lb.

Weight explains much of the pattern, but it does not explain every car.

Next, I would add horsepower and test predictions on new data.

Sources