A way to draw a straight line through scattered points.
We use one numeric X to predict one numeric Y.
September 7, 2026
A way to draw a straight line through scattered points.
We use one numeric X to predict one numeric Y.
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.
\(\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.
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.
fit <- lm(dist ~ speed, data = cars) coef(fit)
## (Intercept) speed ## -17.579095 3.932409