Fitting Linear Models

y <- cars$dist
x <- 1:length(y)
plot(x, y, pch = 20)
fit <- lm(y~x)
abline(fit, col="blue", lwd=2)
fit_last_ten <- lm(y[40:50]~x[40:50])
abline(fit_last_ten, col="red", lwd=2)