2025-02-09

Definition

  • Simple Linear Regression is a statistical regression model that estimates the relationship between an independent variable and dependent variable.

  • Simple Linear Regression Equation: \[ y = \beta_0 + \beta_1 x + \epsilon \]

  • Term Definitions:

    • \(y\) is the independent variable
    • \(x\) is the dependent variable
    • \(\beta_0\) is the y-intercept
    • \(\beta_1\) is the slope
    • \(\epsilon\) is the error

Definition Explained

  • Now you know the equation for Simple Linear Regression. But how do we actually make the calculations to find the equation when given just the data?
  • Step 1: Calculate the estimated slope \[ \hat{\beta_1} = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2} \]
  • Term Definitions:
    • \(\hat{\beta_1}\) is the estimated slope
    • \(x_i\) is the \(i\)th observation of the independent variable
    • \(y_i\) is the \(i\)th observation of the dependent variable
    • \(\bar{x}\), \(\bar{y}\) are the means of \(x\) and \(y\)

Definitions Explained Continued

  • Step 2: Calculate the y-intercept

\[ \hat{\beta_0} = \bar{y} - \hat{\beta_1} \bar{x} \] - \(\hat{\beta_0}\) is the estimated y-intercept

  • Step 3: Put it all together - Insert your answers from Step 1 and Step 2 to complete your linear regresssion equation!

Women Dataset

  • Now let’s take a look at the women data set already provided in R
head(women,5)
##   height weight
## 1     58    115
## 2     59    117
## 3     60    120
## 4     61    123
## 5     62    126
  • As we can see from the first few lines, the dataset provides the height and weight of women.
  • Let’s try to make a simple linear regression model for this data using height as the independent variable and weight as the dependent variable.

Scatterplot

  • Here’s a simple scatterplot so we can start to visualize the data

Adding Linear Regression Line

ggplot(women, aes(x = height, y = weight)) +
  geom_point(color = "black") +
  geom_smooth(method = "lm", se = TRUE, col = "green") + 
  labs(title = "Linear Regression: Women's Weight vs Height", 
       x = "Height (inches)", y = "Weight (lbs)")
## `geom_smooth()` using formula = 'y ~ x'

Plotly Plot