Simple linear regression examines the relationship between one predictor variable and one response variable.
For this example, we will study how vehicle weight affects fuel economy.
2026-09-15
Simple linear regression examines the relationship between one predictor variable and one response variable.
For this example, we will study how vehicle weight affects fuel economy.
A simple linear regression model is:
\[ Y_i = \beta_0 + \beta_1X_i + \epsilon_i \]
Where:
We will use the built-in R dataset mtcars.
Important variables:
mpg = miles per gallonwt = vehicle weight in thousands of poundshp = horsepower## mpg wt hp ## Mazda RX4 21.0 2.620 110 ## Mazda RX4 Wag 21.0 2.875 110 ## Datsun 710 22.8 2.320 93 ## Hornet 4 Drive 21.4 3.215 110 ## Hornet Sportabout 18.7 3.440 175 ## Valiant 18.1 3.460 105
## `geom_smooth()` using formula = 'y ~ x'
Heavier vehicles generally have lower fuel economy.
The estimated regression equation is:
\[ \hat{Y} = b_0 + b_1X \]
## (Intercept) wt ## 37.285126 -5.344472
The slope shows how MPG changes as vehicle weight increases.
The coefficient of determination is:
\[ R^2 = 1 - \frac{SS_{res}}{SS_{tot}} \]
## [1] 0.7528328
A higher \(R^2\) means the model explains more of the variation in MPG.
Residuals help determine whether the linear model is reasonable.
This interactive graph compares weight, horsepower, and fuel economy.
library(ggplot2) model <- lm(mpg ~ wt, data = mtcars) ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + geom_smooth(method = "lm")
Suppose a vehicle weighs 3,000 pounds.
Since wt is measured in thousands:
\[ X = 3 \]
## 1 ## 21.25171
The model predicts the expected MPG for a vehicle weighing 3,000 pounds.