Using the “cars” dataset in R, build a linear model for stopping distance as a function of speed and replicate the analysis of your textbook chapter 3 (visualization, quality evaluation of the model, and residual analysis.)
head(cars)
## speed dist
## 1 4 2
## 2 4 10
## 3 7 4
## 4 7 22
## 5 8 16
## 6 9 10
cars.lm <- lm(dist ~ speed, cars)
ggplot(data = cars, aes(x = speed, y = dist)) +
geom_point(color='blue') +
geom_smooth(method = "lm", se = FALSE)
autoplot(cars.lm)