Linear regression, unfortunately, has found its way into the precaluclus curriculum; the tendency is to stuff too many subjects into the curriculum, especially when it involves using a calculator. I've put together some code for finding the regression line that best fits the data at hand. The code is posted on the Python/Sage page as well as the Sage in the Classroom page and you can see a screenshot (above). I've included it below as well:
r = [[0,76.4], [1,78.5], [2,81.5], [3,87.8], [4,88.4], [5,92.4], [6,94.0], [7,95.0]]
model(x) = a*x+b
a = find_fit(r, model).rhs()
b = find_fit(r,model).rhs()
html("Regression line is %4.2fx+%4.2f"%(a,b))
points(r,color='red',size=20)+ plot(model(a = find_fit(r, model).rhs(),b = find_fit(r,model).rhs()),0,15,xmin = 0,xmax = 10)
The variable r is the set of data points and after declaring the variable a,x,b and
the model ax+b we're ready to solve the problem. This is accomplished through find_fit which returns the values of the variables in a list; a = find_fit(r, model).rhs() gets us the value of a which we format more nicely when printing our answer with html("Regression line is %4.2fx+%4.2f"%(a,b)). After that, we plot the points and regression line on the same graph and print it out.
So now you have, I hope, some useful resources. You can create linear data from an earlier post and find the linear regression line with the code in today's post.