- Simple linear regression is used to study the relationship between two variables.
- It uses one variable to predict another variable.
- In this example, we will look at car weight and miles per gallon.
2026-06-07
Linear regression finds the best fitting straight line through a set of data points.
\[ y = \beta_0 + \beta_1x + \epsilon \]
where:
\[ \sum_{i=1}^{n}(y_i - \hat{y}_i)^2 \]
The regression line is chosen by minimizing the sum of squared differences between the actual values and predicted values.
## `geom_smooth()` using formula = 'y ~ x'
model <- lm(mpg ~ wt, data = mtcars) summary(model)
This code creates a linear regression model using car weight to predict miles per gallon.