The question

Can vehicle weight and horsepower explain differences in fuel economy?

  • Outcome: miles per gallon (mpg)
  • Predictors: weight in 1,000 lb (wt) and horsepower (hp)
  • Data: 32 cars in R’s built-in mtcars dataset

This is an observational teaching dataset. The model describes associations, not causal effects.

Weight and fuel economy

Heavier cars tend to have lower mpg. The line shows the unadjusted relationship.

A two-predictor model

We estimate the mean fuel economy from weight and horsepower:

\[\mathrm{mpg}_i = \beta_0 + \beta_1\,\mathrm{wt}_i + \beta_2\,\mathrm{hp}_i + \varepsilon_i.\]

The fitted equation is:

\[\widehat{\mathrm{mpg}} = 37.23 - 3.88\,\mathrm{wt} - 0.0318\,\mathrm{hp}.\]

Each slope compares cars with the other predictor held fixed.

Horsepower also matters

Larger circles represent heavier cars. Weight and horsepower are related, so a multiple regression separates their associations with mpg.

Reading the estimates

Term Estimate Meaning, holding the other predictor fixed
Weight -3.88 mpg A 1,000 lb increase corresponds to 3.88 fewer mpg
Horsepower -0.032 mpg A 10 hp increase corresponds to 0.32 fewer mpg

The model explains 82.7% of the observed variation in mpg.

The intercept extrapolates to a car with zero weight and zero horsepower, so it has no practical interpretation here.

Observed versus predicted mpg

Hover over a point to identify its car. Distance from the dashed line shows prediction error.

Residual check

Residuals show errors of several mpg. The smooth curve helps reveal departures from a straight-line model.

Uncertainty in the weight slope

A 95% confidence interval for the weight coefficient is:

\[\widehat\beta_1 \pm t_{0.975,\,29}\,\mathrm{SE}(\widehat\beta_1)\]

For these data, it is [-5.17, -2.58] mpg per 1,000 lb.

The interval excludes zero. Under the model assumptions, the data support a negative association between weight and mpg after accounting for horsepower.

Reproduce the analysis

library(ggplot2)
library(plotly)
library(htmlwidgets)

data(mtcars)
fit <- lm(mpg ~ wt + hp, data = mtcars)
summary(fit)
confint(fit)

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  geom_smooth(method = "lm")

The source R Markdown includes all plot code and loads its required packages.

What the model tells us

  • Both higher weight and higher horsepower are associated with lower mpg in this sample.
  • Weight has the larger standardized signal in this fitted model, but units differ.
  • Predictions apply most safely within the weight and horsepower ranges observed in these 32 cars.

Data source: R datasets::mtcars. Analysis and graphics generated from the source R Markdown.