Simple linear regression studies the relationship between:
- one predictor variable \(x\)
- one response variable \(y\)
\[ y = \beta_0 + \beta_1 x + \varepsilon \]
2026-04-13
Simple linear regression studies the relationship between:
\[ y = \beta_0 + \beta_1 x + \varepsilon \]
\[ \hat{y} = b_0 + b_1 x \]
\[ b_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]
\[ b_0 = \bar{y} - b_1 \bar{x} \]
We use the built-in mtcars dataset.
wt = car weightmpg = miles per gallon| mpg | wt | |
|---|---|---|
| Mazda RX4 | 21.0 | 2.62 |
| Mazda RX4 Wag | 21.0 | 2.88 |
| Datsun 710 | 22.8 | 2.32 |
| Hornet 4 Drive | 21.4 | 3.21 |
| Hornet Sportabout | 18.7 | 3.44 |
| Valiant | 18.1 | 3.46 |
From the fitted model:
Weight explains about 75.3% of the variation in MPG, and the relationship is negative.
\[ \widehat{mpg} = 37.29 - 5.34(wt) \]
Interpretation:
We fit a linear model and visualize the relationship.
model <- lm(mpg ~ wt, data = mtcars) ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + geom_smooth(method = "lm")