2025-09-17

What is Simple Linear Regression (SLR)?

Simple linear regression helps us understand the relationship between two variables.

  • One variable predicts another
  • Shows if there is a pattern between them
  • Draws a straight line through data points

Example: Does speed affect required distance to stop?

The Math Behind SLR

The equation for a straight line is:

\[Y = mX + b\]

Where:

  • \(Y\) = what we want to predict
  • \(X\) = what we use to predict
  • \(b\) = the y-axis intercept of the line
  • \(m\) = the slope of the line

Example: Car Data

##   speed dist
## 1     4    2
## 2     4   10
## 3     7    4
## 4     7   22
## 5     8   16
## 6     9   10
  • speed: how fast the car was going (mph)
  • dist: how far it took to stop (feet)

Looking at the Data

Adding a Line Through the Data

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

The R Code for Our Plot

ggplot(cars, aes(x = speed, y = dist)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(title = "Speed vs Distance with Best Fit Line",
       x = "Speed (mph)", 
       y = "Distance (feet)")

Interactive and 3D

Looking at the Results

The general form of our fitted model is: \[\hat{Y} = \hat{\beta_0} + \hat{\beta_1}X\]

## (Intercept)       speed 
##  -17.579095    3.932409

Our Specific Equation and its Meaning: Distance = -17.6 + 3.9 × Speed

  • For every 1 mph faster, cars need approximately 4 more feet to stop
  • The line starts at -17.6 feet, which doesn’t make real sense, but that is the math!

Checking the Model

This displays if our line is or is not a good fit for the data.

Conclusion

What we Learned:

  • Faster cars do take longer to stop
  • Stopping distance can be predicted from speed
  • Linear regression helps us find patterns within data

A Real World Use-case: Simple Linear Regression data on speed verses stopping distance could help set speed limits or impact brake system designs.