Oct 18, 2026

The question

Can a car’s weight help predict its fuel economy?

  • Outcome: miles per gallon (mpg)
  • Predictor: weight, measured in 1,000 lb
  • Data: mtcars, a built-in R dataset of 32 car models
  • Method: simple linear regression

Story: explore the relationship, fit a line, and interpret what it can—and cannot—tell us.

Why this matters

Fuel economy affects running costs and fuel use. Vehicle weight is one plausible predictor, but it is not the only factor.

Our analysis asks whether weight is associated with mpg in this sample. It does not prove that weight alone causes a particular fuel economy.

First look at the data

The scatterplot suggests a negative, roughly linear association: as weight increases, mpg generally decreases. There is still variation around the trend.

What is correlation?

Correlation summarizes the direction and strength of a linear relationship. Pearson’s correlation ranges from \(-1\) to \(1\).

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

  • \(r < 0\): negative linear association
  • \(r \approx 0\): little linear association
  • \(r > 0\): positive linear association

Correlation is unitless and can be affected by unusual observations. It does not establish causation.

Correlation in this sample

In mtcars, \(r = -0.87\). This is a strong negative linear association in this small dataset: heavier cars tend to have lower mpg.

The regression model

Simple linear regression describes the average linear trend in the outcome as the predictor changes.

\[ Y_i = \beta_0 + \beta_1 X_i + \varepsilon_i \]

  • \(Y_i\): mpg for car \(i\)
  • \(X_i\): weight in 1,000 lb
  • \(\beta_0\): intercept; predicted mpg at weight 0 (not practically meaningful here)
  • \(\beta_1\): expected change in mpg for a 1,000 lb increase
  • \(\varepsilon_i\): unexplained variation

The fitted line estimates \(\beta_0\) and \(\beta_1\) from the observed data.

Fitted line and interpretation

The estimated line is:

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

The slope is about -5.34 mpg per additional 1,000 lb. This describes the fitted association in mtcars, not a universal effect for every vehicle.

How much variation does the line explain?

\[ R^2 = 1 - \frac{\sum_i(y_i-\hat{y}_i)^2} {\sum_i(y_i-\bar{y})^2} \]

\(R^2\) is the fraction of sample variation in mpg accounted for by the fitted linear model.

For this model, \(R^2 = 0.753\), or about 75.3%. That is substantial for this sample, but the remaining variation means weight does not tell the whole story.

Interactive view: explore individual cars

Hover over points to inspect car names, weight, mpg, and cylinder count. The interactive plot is useful for identifying observations rather than relying only on a summary statistic.

plot_ly(cars, x = ~wt, y = ~mpg,
        type = "scatter", mode = "markers",
        color = ~cyl,
        text = ~paste0("Model: ", model,
                       "<br>Weight: ", wt, " (1,000 lb)",
                       "<br>MPG: ", mpg,
                       "<br>Cylinders: ", cyl),
        hoverinfo = "text",
        colors = c("#FFC627", "#8C1D40", "#555555")) |>
  layout(title = "Hover to inspect each car",
         xaxis = list(title = "Weight (1,000 lb)"),
         yaxis = list(title = "Miles per gallon"),
         legend = list(title = list(text = "Cylinders")))

R code behind the analysis

# Fit simple linear regression
fit <- lm(mpg ~ wt, data = mtcars)

# Summarize coefficients and model fit
summary(fit)

# Calculate Pearson correlation
cor(mtcars$wt, mtcars$mpg)

# Make a ggplot2 scatterplot with fitted line
ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm", formula = y ~ x)

The code makes the analysis reproducible: the same data and commands can be rerun to regenerate the results and figures.

What should we be careful about?

  • Small sample: only 32 car models are included.
  • Other variables: engine size, horsepower, transmission, and design may also relate to mpg.
  • Model assumptions: a straight-line summary may not capture every pattern; residual diagnostics would help assess fit.
  • Association is not causation: these observational data cannot isolate the causal effect of weight.
  • Extrapolation: avoid using the fitted line for weights far outside the observed range.

Conclusion: the statistical story

  • In mtcars, weight and mpg have a strong negative linear association (\(r = -0.87\)).
  • The fitted slope is about -5.34 mpg per 1,000 lb.
  • The model explains about 75.3% of the sample variation in mpg.
  • Weight is informative, but other factors and the small observational sample limit the conclusions.

Takeaway: a statistical model turns a visual pattern into a quantified relationship—but interpretation and limitations matter as much as the line.

Reproducibility and sources

  • Data: mtcars, included with base R; see ?mtcars in R.
  • Methods: Pearson correlation and ordinary least-squares simple linear regression.
  • Visualizations: ggplot2; interactive scatterplot: plotly.
  • R packages required: ggplot2, plotly, dplyr, tibble, knitr, and rmarkdown.