Question

Can the weight of a car help us predict gas mileage?

  • We use linear regression.
  • The mtcars dataset has 32 cars.
  • wt = weight in 1,000 pounds.
  • mpg = miles per gallon.

Weight vs. Miles Per Gallon

Heavier cars usually have a lower MPG.

Regression

A regression line is written as follows:

\[ y = b_0 + b_1 x \]

For our cars:

\[ mpg = 37.285 - 5.344(\mathrm{wt}) \]

An extra 1,000 pounds is associated with about 5.34 fewer MPG.

Example: A 3,000-pound car

A 3,000-pound car has wt = 3.

\[ mpg = 37.285 - 5.344(3) \]

\[ mpg \approx 21.25 \]

About 21 miles per gallon.

Regression line

The red line shows the model’s predicted average MPG.

Plotly plot

Hold your cursor over the dots to see their values.

R code used for plotly plot

plot_ly(mtcars, x = ~wt, y = ~mpg,
        type = "scatter", mode = "markers") %>%
  layout(xaxis = list(title = "Weight (1,000 lb)"),
         yaxis = list(title = "Miles per gallon"))

Conclusion

  • Heavier cars generally have lower MPG in this dataset.
  • Weight explains about 75% of the variation in MPG (\(R^2 \approx 0.75\)).
  • The result shows an association, not causation.