- Simple Linear Regression (SLR) models the relationship between one predictor (x) and a response (y).
- Equation:
\[ y = \beta_0 + \beta_1 x + \epsilon \]
We’ll use the mtcars dataset in R.
- Predictor: wt
(car weight)
- Response: mpg
(miles per gallon)
The fitted regression line is:
\[
\hat{y} = \hat{\beta}_0 + \hat{\beta}_1 x
\]
## (Intercept) wt ## 37.285126 -5.344472
## `geom_smooth()` using formula = 'y ~ x'
# Fit linear regression fit <- lm(mpg ~ wt, data=mtcars) # Summary of results summary(fit) # Plot regression line ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() + geom_smooth(method="lm")
We test the null hypothesis:
\[
H_0 : \beta_1 = 0 \quad \text{vs} \quad H_a : \beta_1 \neq 0
\]
- If p-value < 0.05 → reject \(H_0\).
- Conclude there is a significant linear relationship.