2024-03-17

Introduction to Simple Linear Regression

  • Simple Linear Regression is used to estimate the relationship between two quantitative variables
  • Generally, you can use it:
    • To determine how strong the relationship is between two variables
    • To see the value of the dependent variable at a certain independent variable’s value

Simple Linear Regression Formula

  • Formula:
  • \[ Y = \beta_0 + \beta_1 X + \epsilon \]
  • \(Y\) is the dependent variable
  • \(X\) is the independent variable
  • \(\beta_0\) is the intercept
  • \(\beta_1\) is the slope
  • \(\epsilon\) is the error term

More Information about Parameters

  • The parameters (\(\beta_0\) and \(\beta_1\)) in the simple linear regression model are estimated using the method of least squares
  • These types of least squares estimates minimize the sum of squared residuals (the differences between observed and predicted values)

Ex: Height vs. Weight

  • Let’s take an example where we want to see the relationship between height and weight. We assume that weight (\(Y\)) can be predicted by height (\(X\)) using a simple linear regression model.

  • The new formula becomes: \[ Weight = \beta_0 + \beta_1 \times Height + \epsilon \]

Understanding of the Results

  • The intercept (\(\beta_0\)) represents the estimated weight when the height is zero
  • The slope (\(\beta_1\)) represents the change in weight for every unit increase in height. It tells how strong the relationship is between two variables.

Ex: Scatterplot and Regression Line

height <- c(60, 62, 64, 66, 68, 70, 72, 74)
weight <- c(120, 130, 140, 150, 160, 170, 180, 190)

model <- lm(weight ~ height)

library(ggplot2)
ggplot(data = data.frame(height, weight), aes(x = height, y = weight)) +
  geom_point() + 
  geom_smooth(method = "lm", se = FALSE) + 
  labs(title = "Scatterplot of Height vs. Weight",
       x = "Height",
       y = "Weight")
## `geom_smooth()` using formula = 'y ~ x'

Ex: Scatterplot and Regression Line

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

Ex. Line Plot for Regression Equation

Ex. Plotly Scatter Plot

  • Please see Word Document!