2024-02-03

Simple Linear Regression

Simple linear regression is used to analyze the relationship between two numerical continuous variables.

The assumptions to make the model are the following:

  • Normal Distribution
  • Linearity
  • Independent observations

Best Fitting Line

The equation for the best fitting line is the following: \[ \hat{y}_i = \beta_0 + \beta_1x \] From the scatter plot example, we will see different observations and try to find a linear model that can help predict point y using x. In this case, we will predict the stopping distance using the speed.

Example

ggplot(data = cars, aes(x = speed, y = dist)) +
  geom_point()

Example with model

Error

From the example, we can see that the model is a good fit but most of the points are above or below the line. This is called the residual, \(e_i\). It is calculated as the following:

\[ e_i = y_i - \hat{y}_i \] \(y_i\) is the actual point \(i\) and \(\hat{y}_i\) is the point \(i\) in the model. If the residual is positive that means the point is above the line and if it is negative it is below the line.

Residual Plot

This plot illustrates the residuals and how well the model fits each data plot. The closer to the line, the smaller the error.

Uses of Simple Linear Regression

The Simple Linear Regression model helps us understand if there is a significant relationship between an independent and a dependent variable. It is also used to predict a response variable based on a predictor variable. It is used in multiple fields and it is an important tool that can inform economics and public policy.