2025-03-14

1. What is Linear Regression?

  • A statistical method modeling the relationship between independent and dependent variables

  • Equation:
    \[ Y = \beta_0 + \beta_1 X + \epsilon \]

2. The Equation (in more detail)

  • Equation, again:
    \[ Y = \beta_0 + \beta_1 X + \epsilon \]

  • \(\beta_0\) is the intercept

  • \(\beta_1\) is the slope

  • \(\epsilon\) is the error term

3. Example with R

##          x         y
## 1 5.037492  8.794434
## 2 4.631495  9.366618
## 3 2.257339  4.346065
## 4 3.801665  8.414071
## 5 5.589090  9.750422
## 6 5.779589 11.232558

4. Scatter Plot with Regression Line

library(ggplot2)
ggplot(data, aes(x=x, y=y)) +
  geom_point(color="yellow") +
  geom_smooth(method="lm", color="pink") +
  ggtitle("Linear Regression: Scatter Plot with Line") +
  theme_minimal()

5. Residual Plot

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

ggplot(data, aes(x=x, y=residuals)) +
  geom_point(color="purple") +
  geom_hline(yintercept=0, linetype="dashed") +
  ggtitle("Residual Plot") +
  theme_minimal()

6. 3D Plot

library(plotly)
plot_ly(data, x=~x, y=~y, z=~residuals, type="scatter3d", mode="markers") %>%
  layout(title="3D Plot")

7. Where is this useful?

Many fields use linear regression!

Finance- to predict stock prices

Engineering- to model strength of materials under varying conditions

Biology- population growth for example

Etc.

8. Conclusion

  • Simple Linear Regression is useful for a plethora of fields such as engineering, biology, and finance

  • Regressions are useful for predictions

Thank you!