2025-10-18

Definition

  • analyze a relationship between a dependent variable and one independent variable
  • attempts to determine strength between dependent and independent variable

Dependent and Independent Variables

  • Independent: inputs to a system and may take on different values freely
  • Dependent: values that change as a consequence of changes in other values in the system

Equation

\[ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i \]

  • \(y_i\) = response
  • \(x_i\) = predictor
  • \(\beta_0\) = y-intercept
  • \(\beta_1\) = slope
  • \(\varepsilon_i\) = random error

Simple Linear Regression Example

Interpreting Simple Linear Regression

’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.

R Code

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)

Another Example