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.
Can the weight of a car help us predict gas mileage?
Heavier cars usually have a lower MPG.
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.
A 3,000-pound car has wt = 3.
\[ mpg = 37.285 - 5.344(3) \]
\[ mpg \approx 21.25 \]
About 21 miles per gallon.
The red line shows the model’s predicted average MPG.
Hold your cursor over the dots to see their values.
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"))