In order to fit the regression line, we use the command lm()
. The lm()
command produces a large amount of information, which we will want to extract as we need it, so we save the information to another variable name model.
model = lm(olym$Time~olym$Year)
To add the regression line to the scatterplot, we can extract the linear equation from model and add the line to the scatterplot.
plot(olym$Year, olym$Time, xlab="Year of Olympic Games", ylab="Winning Time of 1500m Race (secs)");abline(model)
We can also extract the y-intercept and slope from the model to determine the regression equation:
coef(model)