2026-02-09

What is Simple Linear Regression?

We model the relationship between a response variable \(Y\) and a predictor \(X\):

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

where:
- \(\beta_0\) is the intercept
- \(\beta_1\) is the slope
- \(\varepsilon\) is random error

Estimating the Parameters

The slope estimator is:

\[ \hat{\beta}_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]

The intercept estimator is:

\[ \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x} \]

Data

For this example, I will generate data with the following command:

set.seed(123)

x <- rnorm(100, mean = 10, sd = 2)
y <- 3 + 1.5 * x + rnorm(100, sd = 2)

data <- data.frame(x, y)

Plotting Data (Scatter Plot)

Utilizing Regression Line

Conclusion

  • Simple linear regression models linear relationships between variables
  • ggplot helps visualize the relationship
  • R makes it easy to estimate and visualize statistical models
  • This project was ultimately to check my skills with certain tools