The question

How does vehicle weight relate to fuel economy?

A heavier car may require more fuel to move. We can examine whether this pattern appears in real measurements.

  • Explanatory variable: vehicle weight, in 1,000 pounds.
  • Response variable: fuel economy, in miles per US gallon (mpg).
  • Method: simple linear regression describes the average relationship with a straight line.

Higher mpg means a car travels farther on one gallon.

The data: 32 cars from the 1970s

The built-in R dataset mtcars contains measurements for 32 automobiles from the 1974 Motor Trend US magazine.

  • Weight ranges from 1.513 to 5.424 thousand pounds.
  • Fuel economy ranges from 10.4 to 33.9 mpg.
  • All 32 cars have recorded weight and mpg values.

These are historical observations, not a random sample of today’s cars. Engine design, horsepower, and other characteristics may also matter.

Source: R’s datasets::mtcars documentation. No external data file is needed.

Heavier cars generally have lower mpg

The downward pattern supports a negative association. The gold line summarizes the trend, while the points show variation around it.

Mathematics: the straight-line model

For car \(i\), let \(x_i\) be weight and \(y_i\) be mpg:

\[y_i = \beta_0 + \beta_1 x_i + \epsilon_i.\]

  • \(\beta_0\): intercept, the modeled mean mpg when weight is zero.
  • \(\beta_1\): slope, the change in modeled mean mpg per additional 1,000 lb.
  • \(\epsilon_i\): variation that weight alone does not explain.

The fitted line is \(\widehat y_i=b_0+b_1x_i\).

A zero-weight car is outside the data, so the intercept is a mathematical starting point rather than a practical prediction.

Mathematics: choosing the best line

Least squares chooses the coefficients that minimize squared residuals:

\[\mathrm{SSE}=\sum_{i=1}^{n}(y_i-\widehat y_i)^2.\]

\[b_1=\frac{\sum_{i=1}^{n}(x_i-\bar x)(y_i-\bar y)} {\sum_{i=1}^{n}(x_i-\bar x)^2},\qquad b_0=\bar y-b_1\bar x.\]

A residual is the observed mpg minus the fitted mpg. Squaring prevents positive and negative errors from canceling and gives larger errors more weight.

R code: fit the model and draw the trend

library(ggplot2)
library(plotly)
data(mtcars)
fit <- lm(mpg ~ wt, data = mtcars)
summary(fit)

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(x = "Weight (1,000 lb)", y = "Fuel economy (mpg)")

lm() fits the regression. summary() reports its coefficients and fit. The line in the earlier chart uses the same regression model.

The fitted relationship

\[\widehat{\mathrm{mpg}}=37.29-5.34\times\mathrm{weight}.\]

An additional 1,000 lb is associated with approximately 5.34 fewer mpg in the fitted model.

At 3,000 lb, the fitted mean is 21.3 mpg. At 4,000 lb, it is 15.9 mpg.

\(R^2 = 0.753\): the fitted line accounts for about 75.3% of the observed variation in mpg in this dataset.

This describes association. It does not prove that changing weight alone causes this difference.

Weight does not explain every difference

Cars above zero outperform the fitted line. Several high fitted-mpg cars have positive residuals, suggesting possible curvature. A straight line is useful, but imperfect.

Explore individual cars interactively

Hover to identify a car. Click a legend entry to hide or show a cylinder group. The groups overlap, but heavier cars tend to have more cylinders.

What did we learn?

In these 32 cars, heavier vehicles generally have lower fuel economy.

  • The fitted decrease is about 5.34 mpg per additional 1,000 lb.
  • The line accounts for roughly 75.3% of observed mpg variation.
  • Residuals show that individual cars can differ substantially from the fitted line.

A useful next step would compare models that also include horsepower or cylinders, then evaluate predictions on new data.

Use this example to understand regression, rather than to predict today’s cars or the effect of modifying a specific car.

Sources and reproducibility

  • Data: R Core Team, datasets::mtcars, Motor Trend Car Road Tests. Documentation credits Henderson and Velleman (1981), Biometrics, 37, 391–411. See ?mtcars in R.
  • Methods: DAT 301, Simple Linear Regression, Sabiha Mahzabeen, course notes. Applied here to a different dataset and question.
  • Presentation: DAT 301 Module 4 ioslides and Plotly materials, and HW3 instructions.
  • Software: R, rmarkdown, ggplot2, and plotly.

All analysis and plots are generated from the Rmd file. The dataset is included with R. No supporting image or CSV files are required.