- analyze a relationship between a dependent variable and one independent variable
- attempts to determine strength between dependent and independent variable
2025-10-18
\[ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i \]
’miles per gallon is the dependent variable and weight is the independent variable. The line represents the best fit and the model is used to predict the miles per gallon based on the weight of the car.
library(ggplot2)
data("mtcars")
gg_lm <- ggplot(mtcars, aes(x = wt, y = mpg)) +
geom_point(color = "blue") +
geom_smooth(method = "lm", color = "red", se = FALSE) +
labs(title = "Weight and Miles Per Gallon Linear Regression") +
theme_minimal()
ggplotly(gg_lm)