The question

Can a vehicle’s weight help explain its fuel economy?

We will use the built-in mtcars data set, which contains 32 automobile models.

  • Outcome: miles per gallon (mpg)
  • Predictor: weight in thousands of pounds (wt)
  • Goal: summarize the relationship, quantify uncertainty, and make a prediction

The simple linear regression model

For vehicle \(i\), simple linear regression writes fuel economy as

\[ Y_i = \beta_0 + \beta_1 x_i + \varepsilon_i, \]

where \(Y_i\) is mpg, \(x_i\) is weight, and \(\varepsilon_i\) captures variation not explained by weight.

If \(\beta_1 < 0\), heavier vehicles tend to have lower fuel economy.

Estimating the line

Ordinary least squares chooses coefficients that minimize the sum of squared residuals:

\[ (\hat\beta_0, \hat\beta_1) = \underset{b_0,b_1}{\operatorname{argmin}}\; \sum_{i=1}^{n} \left[Y_i - (b_0 + b_1x_i)\right]^2. \]

The fitted value is \(\widehat{Y}_i = \hat\beta_0 + \hat\beta_1x_i\) and the residual is \(e_i = Y_i - \widehat{Y}_i\).

Weight and fuel economy

Residuals: what the line misses

The residual plot is not perfectly flat, but it has no dramatic funnel pattern. It is a useful reminder to check assumptions before relying on a model.

An interactive 3D view

Rotate, zoom, and hover over points. The 3D view suggests that both weight and horsepower are connected with mpg, even though our simple model uses only weight.

R code that creates the regression plot

ggplot(cars, aes(x = wt, y = mpg)) +
  geom_point(size = 3, color = "#2563eb", alpha = 0.85) +
  geom_smooth(method = "lm", se = TRUE, color = "#b45309") +
  labs(x = "Weight (1,000 lb)", y = "Miles per gallon") +
  theme_minimal(base_size = 17)

What does the fitted model say?

The fitted equation is

\[ \widehat{mpg} = 37.29 - 5.34\,(weight). \]

  • Each additional 1,000 lb is associated with about 5.34 fewer mpg on average.
  • Weight alone explains about 75.3% of the variation in mpg.

A prediction example

For a 3,000-lb vehicle, the fitted mpg is 21.3.

A 95% prediction interval is [14.9, 27.6] mpg.

The interval is wider than a confidence interval because it accounts for both uncertainty in the mean line and variation among individual vehicles.

Key takeaways

  1. Simple linear regression describes how an outcome changes with one predictor.
  2. In this data, heavier vehicles tend to have lower fuel economy.
  3. The line is useful for summarizing and predicting, but residual checks matter.
  4. Other variables, such as horsepower, may improve the model.

Main idea: a regression line is a compact, evidence-based description of a relationship - not proof of causation.