+
Common Core: S.ID.6a S.ID.6c

# Finding the Least-Squares Line Author: Ryan Backman
##### Description:

Calculate the slope and y-intercept for a least-squares line.

(more)

Sophia’s self-paced online courses are a great way to save time and money as you earn credits eligible for transfer to many different colleges and universities.*

No credit card required

37 Sophia partners guarantee credit transfer.

299 Institutions have accepted or given pre-approval for credit transfer.

* The American Council on Education's College Credit Recommendation Service (ACE Credit®) has evaluated and recommended college credit for 32 of Sophia’s online courses. Many different colleges and universities consider ACE CREDIT recommendations in determining the applicability to their course and degree programs.

Tutorial

## Video Transcription

Hi. This tutorial covers finding the least-squares line. So let's start with a fairly simple data set, so just five values. So the raw data's here. The graph is here. OK.

So now recall that the least-squares line is a best-fit line that is found through a process of minimizing the sum of the squared residuals. OK. Now, the general form for a least-squares equation, or the equation of a least-squares line, is y hat equals b sub 0 plus b sub 1 times x, where b sub 0 is the y-intercept, and b sub 1 is the slope. So it's always the y-intercept plus the slope times x is going to equal what you're y hat value is. So we're going to use that equation in a minute. That's just the general form.

Now, the least-squares line always passes through the point x bar, y bar. That point is sometimes called the centroid. All that is is the average x value comma the average y value. Even if this point isn't in the data set, the line will still always pass through that point.

And then the slope can be found using the following formula. So b1 equals r, which is the correlation coefficient, times s sub y over s sub x. And if you multiply the correlation coefficient times this ratio, you're going to get the slope. OK. So we'll use that equation in a minute also.

So now let's find the equation for the least-squares line. So I've reproduced the data here. So the first thing that we need is that centroid, so x bar, y bar. And that just comes from, again, the average of the x list and the y list.

So what I have is-- I have the data in my calculator. And what I can do now is go ahead and find those values. So x bar is 3.8. So this is going to be 3.8 comma y bar. If I scroll down, y bar is 2.4. So 2.4 is my x bar, y bar, or my centroid.

OK. Now, I also know that b1 is going to equal r times sy over sx. So now I need sy and sx-- so the standard deviation of the y values, standard deviation of the x values. These are both sample standard deviations.

And actually, from my calculator, these are in the same screen. So sy is 1.1401. And I'm going to reproduce that to a pretty high degree of accuracy, so 1.14018.

And then sx-- scroll down here-- whoops-- or scroll up-- is 1.3038 about, so 1.30384. OK. So that's part-- that's most of my equation for b1.

I still need to get r. So r, we could either go through the formula-- again, my calculator can find r. So r ends up being 0.57177-- so 0.57177.

Now that I have all the values that I need. I'm going to next find the value of my slope. So I'm going to take r times the ratio of these two values. And I will do that on the calculator. So it's going to be 0.57177 times 1.14018 divided by 1.30384. OK. And if I hit Enter, I get a value very close to 0.5. So I'm going to round that to 0.5 because it does seem like it's very close to that. So b is equal to 0.5.

So we are-- remember, the equation for my least-squares line is y hat equals b sub 0 plus b sub 1 x. So I have b sub 1. The next thing I need is b sub 0. So I need to find that y-intercept.

And what I'm going to do is-- since I know the least-squares line has to go through this point, x bar, y bar, I'm going to use that point to solve for b sub 0. So all I'm going to do is I'm going to take my 3.8-- because that's my-- or sorry-- I'm going to start with my 2.4. That's going to be my-- it's y bar. But since it's on this line, it'll be a value of y hat.

So it's going to be 2.4 equals b sub 0 plus the slope I just calculated, 0.5, times my x value-- so in this case, x bar, because that point will be on the line. And so now I'm just going to use some algebra to solve for b sub 0. So I'm going to first multiply 0.5 times 3.8. So if I do that, 3.8 times 0.5 is 1.9.

And then I'm going to go ahead and subtract 1.9 from both sides. And 2.4 minus 1.9 is 0.5 equals b sub 0. That would be 0. So b sub 0 is equal to 0.5. So my y-intercept is equal to 0.5.

OK. So what my final equation will then look like is y hat equals 0.5, which was my y-intercept, plus my slope, which is also 0.5, x. So that is my line of best fit, or my least-squares line. So that's usually how you calculate it.

If you were to have to do it by hand, this is how you would do it. Generally, there are functions built into calculators as well as computer programs, where all you have to do is just enter in the data. And using that function, it will give you this equation. So you won't have to go through all of the steps here.

So that has been your tutorial on finding the least-squares line. Thanks for watching.

Terms to Know
Least-Squares Regression Line

The line of best fit, according to the method of Least-Squares.

x-bar

The mean of the explanatory variable.

y-bar

The mean of the response variable.

Formulas to Know
Slope of Least Squares Line Rating