Do heavier cars get fewer miles per gallon?
A scatterplot shows the pattern. A regression line puts a number on it.
Do heavier cars get fewer miles per gallon?
A scatterplot shows the pattern. A regression line puts a number on it.
mtcars contains 32 cars from the 1973–1974 model years.
Weight is in 1,000 pounds. Mileage is in miles per US gallon.
Source: R’s mtcars documentation; Motor Trend (1974).
Heavier cars tend to get lower MPG.
Correlation measures how closely the points follow a straight-line pattern.
Here, r = -0.868. The relationship is strong and negative.
That does not prove that weight causes the difference in MPG.
\[ \mathrm{MPG}_i = \beta_0 + \beta_1\mathrm{Weight}_i + \varepsilon_i \]
\(\beta_0\) is the intercept and \(\beta_1\) is the slope.
\(\varepsilon_i\) is the part the line does not explain.
Weight is measured in 1,000 pounds.
The residual is the observed MPG minus the fitted MPG:
\[ e_i = y_i - \widehat{y}_i \]
R chooses the line that makes the sum of squared residuals smallest:
\[ \mathrm{SSE} = \sum_{i=1}^{32}(y_i-\widehat{y}_i)^2 \]
fit <- lm(mpg ~ wt, data = cars) round(coef(fit), 2)
## (Intercept) wt ## 37.29 -5.34
The fitted line is:
\[ \widehat{\mathrm{MPG}} = 37.29 - 5.34\times\mathrm{Weight} \]
The line explains about 75% of the variation in MPG in these cars.
An extra 1,000 pounds is associated with about 5.34 fewer MPG.
For a 2,500-pound car, the line gives 23.9 MPG.
For a 3,500-pound car, it gives 18.6 MPG.
Hover over a point to see the car. Drag to zoom; double-click to reset.
The heavier cars generally get fewer miles per gallon.
Weight does not explain everything. Engine design could matter too.
These are older cars, so the same numbers may not apply to cars today.
Data: R datasets package, help(“mtcars”).
Methods: R documentation for lm() and cor().
Plots: ggplot2 and Plotly.