We will use the built-in mtcars dataset.
- wt: car weight (in 1000 lbs)
- mpg: miles per gallon
Goal: understand how weight affects fuel efficiency.
We will use the built-in mtcars dataset.
Goal: understand how weight affects fuel efficiency.
Simple linear regression describes the relationship between one predictor variable and one response variable.
\[ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i \]
Estimated coefficients:
Estimated model:
\[ \hat{y} = b_0 + b_1 x \]
Interpretation:
For every increase of 1 (1000 lbs) in weight, mpg decreases by about 5.34.
\[ H_0 : \beta_1 = 0 \]
\[ H_a : \beta_1 \ne 0 \]
If the p-value is small, we reject \(H_0\).
Explore how weight, mpg, and horsepower relate in 3D.
ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(size = 3, color = "#8C1D40") +
geom_smooth(method = "lm", se = TRUE, color = "black") +
labs(
title = "MPG vs Weight",
x = "Weight (1000 lbs)",
y = "Miles per Gallon"
) +
theme_minimal(base_size = 18)
Regression is a powerful tool.