2024-03-21

Learning the Basics

  • Regression model used to find a linear relationship to describe a correlation between an independent and dependent variable
  • A linear relationship is assumed between the variables
  • Regression Line: line of best fit between data points

How is it done?

  • Regression Lines are found through minimizing the sum of squared residuals
  • Residuals: difference between the actual and predicted value

Understanding the Equation

\[ Y = \beta_0 + \beta_1 X + \varepsilon \]

  • \(Y\): Dependent variable
  • \(X\): Independent variable
  • \(\beta_0\): Y intercept
  • \(\beta_1\): Slope coefficient
  • \(\varepsilon\): Random error

Calculating Residuals

\[ e_i = y_i - \hat{y}_i \]

  • \(e_i\) is the residual for observation \(i\),
  • \(y_i\) is the observed value for observation \(i\),
  • \(\hat{y}_i\) is the predicted value for observation \(i\).

Example Plot 1

  • Below is an example plot of a scatter plot with a linear regression line
library(ggplot2)
library(plotly)

x <- rnorm(100)
y <- 2.5 * x + rnorm(100)
data <- data.frame(x, y)

model <- lm(y ~ x, data = data)

Example Plot 1

Example Plot 2

  • Plot showing the residuals that are used when calculating a linear regression line
x <- rnorm(100)
y <- 2.5 * x + rnorm(100)
data <- data.frame(x, y)

model <- lm(y ~ x, data = data)

residuals <- resid(model)

resid_data <- data.frame(x = data$x, residuals)

Example Plot 2

Example Plot 3:

  • Histogram to assess normality of linear regression model

Linear Regression Use Cases

  • Predictive Modeling
  • Trend Analysis
  • Risk Assessment
  • Forecasting