Source: Graphs created by Katherine Williams
This tutorial introduces the least-squares line.
The least-squares line is one particular kind of line of best fit, and it's probably the most commonly used one. You can use Excel, or other statistical softwares, or graphing calculators in order to create some for yourself for a set of data.
Now, with the least-squares line, what the program is doing for you-- and in a later tutorial, what we'll do by hand-- is calculating the minimum. It's trying to minimize the sum of the squares of the vertical distances from the line of best fit to each point. So let's kind of walked through a little bit what that means and show some examples.
So here, we have this blue line. That's our least-squares line, our line of best fit. Each with the little blue plus signs is a data point. So the vertical distance is from the point straight down to the line-- from the point straight down or from the point up. Now, you square those differences-- so it doesn't matter whether or not the point was above or below the line-- and then are trying to minimize those distances. I'll show another kind of exciting applet to help us understand this better.
So here, this is showing a set of 1, 2, 3, 4, 5 data points. And we're able to change the slope and the intercept in order to change the sums of the square. So it's hard to see, but this is 317. And you can see by the size of the squares, this is not a very good line of fit for this. But as we change the slope, the sum of the squares is going down. And we're starting to get a better and better fit-- a better and better least-squares line.
Now, it's hard to kind of judge and eyeball where it should be. But as I make this box smaller or larger, one of the other boxes is changing size as well. So the best line is right here. So even though they're still kind of medium-sized boxes and very small boxes, it's minimizing that size of the squares total.
The sum of squares here is only 3.6, whereas, before, we had one that was almost 300. So what this line is doing-- this least-squares line-- is it's making the squares, the sum of all of them, as small as possible to give us our best fit line. This has been your tutorial introducing least-squares lines.