- A way to fit a straight line through data
- The line shows how one variable \(y\) changes when another variable \(x\) changes
- We can then use the line to make predictions
\[\widehat{y} = b_0 + b_1 x\]
We could draw lots of different lines, so we pick the one where the points are as close to the line as possible. This is the line with the smallest sum of squared errors:
\[SSE = \sum_{i=1}^n (y_i - \widehat{y}_i)^2\]
The built-in R data set cars has the speed (mph) and stopping distance (ft) of 50 cars.
fit = lm(dist ~ speed, data = cars) coef(fit)
## (Intercept) speed ## -17.579095 3.932409
So the fitted line is
\[\widehat{y} = -17.58 + 3.93 x\]
Each extra mph adds about 3.9 feet to the stopping distance.
How far does a car going 20 mph need to stop?
We plug \(x = 20\) into the line:
\[\widehat{y} = -17.58 + 3.93 \times 20 \approx 61\]
So it would need about 61 feet to stop.
With two \(x\) variables, \(\widehat{y} = b_0 + b_1 x_1 + b_2 x_2\), the line becomes a plane.
For example, predicting a tree’s volume from its girth and height:
cars data, each extra mph adds about 3.9 feet of stopping distance