Welcome to my linear regression slideshow!!

This is a showcase of plotly, ggplots, and math latex in r using ioslides to showcase linear regression.

1st ggplot graph

1st ggplot code:

ggplot(df, aes(x = x, y = y)) + geom_point(color = “#8C1D40”, size = 2) + labs(title = “Scatter Plot of Simulated Data”, x = “X variable”, y = “Y variable”) + theme_minimal()

2nd ggplot graph

## `geom_smooth()` using formula = 'y ~ x'

2nd ggplot code

ggplot(df, aes(x = x, y = y)) + geom_point(color = “steelblue”) + geom_smooth(method = “lm”, se = FALSE, color = “#8C1D40”) + labs(title = “Linear Regression Fit”, x = “X variable”, y = “Y variable”) + theme_minimal()

Code for 2nd ggplot:

## A marker object has been specified, but markers is not in the mode
## Adding markers to the mode...

The Linear Regression Model

In simple linear regression, we model the relationship between a dependent variable \(y\)
and an independent variable \(x\) as:

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

where:

  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\varepsilon_i\) = random error term for observation \(i\)

The goal is to estimate \(\beta_0\) and \(\beta_1\) so that the line best fits the data.

Least Squares Estimation

The least squares method minimizes the sum of squared residuals:

\[ \text{Minimize: } S(\beta_0, \beta_1) = \sum_{i=1}^n (y_i - \hat{y_i})^2 \]

where:

\[ \hat{y_i} = \beta_0 + \beta_1 x_i \]

The formulas for the estimates are:

\[ \hat{\beta_1} = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})} {\sum (x_i - \bar{x})^2}, \quad \hat{\beta_0} = \bar{y} - \hat{\beta_1}\bar{x} \]