What is simple linear regression?

  • Simple linear regression describes the relationship between two variables.
  • It uses a straight line to predict one variable from the other.
  • Example: hours worked vs weekly earnings -Not based on real data -Predictor is hours worked, outcome is earnings

\[ \hat{y} = b_0 + b_1x \]

  • \(x\): hours worked per week
  • \(\hat{y}\): predicted weekly earnings before taxes
  • \(b_0\): predicted earnings when hours worked is zero
  • \(b_1\): increase in predicted earnings for each additional hour worked

example data

  • Data represent eight different schedules
  • Weekly earnings are before taxes.
  • Pay rate is $16 an hour.
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
earnings_data <- data.frame(
  hours = c(5, 10, 15, 20, 25, 30, 35, 40)
)

earnings_data$earnings <- 16 * earnings_data$hours

earnings_data
##   hours earnings
## 1     5       80
## 2    10      160
## 3    15      240
## 4    20      320
## 5    25      400
## 6    30      480
## 7    35      560
## 8    40      640

Hours worked versus weekly earnings

Each point represents one work schedule. As hours increase, weekly earnings increase.

Fitting a regression line

Using the regression equation

Our fitted equation is:

\[ \hat{y} = 0 + 16x \]

For someone working 25 hours:

\[ \hat{y} = 0 + 16(25) = 400 \]

  • Predicted weekly earnings are $400 before taxes.
  • The slope is 16: each additional hour adds $16.
  • The intercept is 0: working zero hours gives $0 in earnings.

Explore the earnings data

What can we conclude?

  • Simple linear regression uses a straight line to predict an outcome.
  • In the example, each additional hour worked adds $16 to weekly earnings.
  • The line fits perfectly because we created the data using a fixed hourly wage.
  • Real earnings data may differ because of overtime, different pay rates, paid time off, etc.