September 7, 2026

What is simple linear regression

A way to draw a straight line through scattered points.

We use one numeric X to predict one numeric Y.

The model

The fitted line is

\[Y = \beta_0 + \beta_1 X + \varepsilon\]

\(Y\) is what we predict. \(X\) is what we know, \(\varepsilon\) is leftover error.

Slope and intercept

\(\beta_0\) is the intercept, the value of \(Y\) when \(X\) is zero.

\(\beta_1\) is the slope, how much \(Y\) changes when \(X\) goes up by one.

An example in data

R has a built in data set called cars.

speed is how fast a car was going.

dist is how far it took to stop.

We treat speed as X and stopping distance as Y.

Scatterplot

Fitted line

Interactive look

The code

fit <- lm(dist ~ speed, data = cars)
coef(fit)
## (Intercept)       speed 
##  -17.579095    3.932409