Linear Regression

The Data

The following data consist of SAT and GPA information for 105 students who graduated from a state university with a B.S. in computer science.

data = 
        Import["/Users/derekbruff/Documents/Teaching/Math 20/linear \
regression/sat.txt", "TSV"];

MatrixForm[data]

Is there a correlation between high school GPA and university GPA?

highGPAunivGPA = 
        Transpose[{Transpose[data][[1]], Transpose[
                data][[5]]}];

MatrixForm[highGPAunivGPA]

highGPAunivGPA = Drop[highGPAunivGPA, 1];

Here is university GPA (vertical axis) plotted versus high school GPA (horizontal axis).

p1 = 
      ListPlot[highGPAunivGPA, PlotRange -> {{2, 4}, {2, 4}}]

The function Fit computes the least-squares line for a given data set.  This is the line that best "fits" the data in a certain sense.

y = Fit[highGPAunivGPA, {1, x}, x]

p2 = Plot[y, {x, 2, 4}]

Graphing the line and data shows that the least-squares line does seem to fit the data.

Show[p1, p2]

Is there a correlation between SAT scores and university GPA?

totalSATunivGPA = 
        Transpose[{Transpose[data][[2]] + Transpose[
                  data][[3]], Transpose[
                data][[5]]}];

MatrixForm[totalSATunivGPA]

totalSATunivGPA = Drop[totalSATunivGPA, 1];

p1 = 
      ListPlot[totalSATunivGPA, PlotRange -> {{1000, 1500}, {2, 4}}, 
        PlotStyle -> PointSize[0.01]]

y = Fit[totalSATunivGPA, {1, x}, x]

p2 = Plot[y, {x, 1000, 1500}]

Show[p1, p2]

Can we predict university GPA from math and verbal SAT scores?

mathSATverbSATunivGPA = 
        Transpose[{Transpose[data][[2]], Transpose[
                data][[3]], Transpose[
                data][[5]]}];

MatrixForm[mathSATverbSATunivGPA]

mathSATverbSATunivGPA = Drop[mathSATverbSATunivGPA, 1];

Fit[mathSATverbSATunivGPA, {1, m, v}, {m, v}]