yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Calculating the equation of a regression line | AP Statistics | Khan Academy


5m read
·Nov 11, 2024

In previous videos, we took this by variant data and we calculated the correlation coefficient. Just as a bit of a review, we have the formula here, and it looks a bit intimidating. But in that video, we saw all it is, is an average of the product of the z-scores for each of those pairs. And as we said, if R is equal to one, you have a perfect positive correlation. If R is equal to negative one, you have a perfect negative correlation, and if R is equal to zero, you don't have a correlation.

But for this particular bivariate data set, we got an R of 0.946, which means we have a fairly strong positive correlation. What we're going to do in this video is build on this notion and actually come up with the equation for the least squares line that tries to fit these points. So before I do that, let's just visualize some of the statistics that we have here for these data points. We clearly have the four data points plotted, but let's plot the statistics for X.

So the sample mean and the sample standard deviation for X are here in red. Actually, let me box these off in red so that you know that's what is going on here. So the sample mean for X, and it's easy to calculate (1 + 2 + 2 + 3 / 4) is (8 / 4), which is (2). So we have (X_{\text{mean}} = 2) right over here.

Then this is one standard deviation above the mean, and this is one sample standard deviation below the mean. We could do the same thing for the Y variables. So the mean is three, and this is one sample standard deviation for Y above the mean, and this is one sample standard deviation for Y below the mean. Visualizing these means, especially their intersection and also their standard deviations, will help us build an intuition for the equation of the least squares line.

So generally speaking, the equation for any line is going to be (Y = mx + b), where this is the slope and this is the Y-intercept for the regression line. We'll put a little hat over it so you would literally say (\hat{Y}). This tells you that this is a regression line that we're trying to fit to these points.

First, what is going to be the slope? Well, the slope is going to be (R) times the ratio between the sample standard deviation in the Y direction over the sample standard deviation in the X direction. This might not seem intuitive at first, but we'll talk about it in a few seconds, and hopefully, it'll make a lot more sense.

But the next thing we need to know is, alright, if we can calculate our slope, how do we calculate our Y-intercept? Well, like you first learned in Algebra 1, you can calculate the Y-intercept if you already know the slope by saying, "What point is definitely going to be on my line?" For a least squares regression line, you're definitely going to have the point ( (\text{sample mean of } X, \text{sample mean of } Y)).

So you're definitely going to go through that point. Before I even calculate for this particular example, where in previous videos we calculated the (R) to be (0.946) or roughly equal to that, let's just think about what's going on. Our least squares line is definitely going to go through that point.

Now, if (R) were one, if we had a perfect positive correlation, then our slope would be the standard deviation of Y over the standard deviation of X. So if you were to start at this point, and if you were to run your standard deviation of X and rise your standard deviation of Y, well, with a perfect positive correlation, your line would look like this.

That makes a lot of sense because you're looking at your spread of Y over your spread of X. If (R) were equal to one, this would be your slope: standard deviation of Y over standard deviation of X. That has parallels to when you first learn about slope, change in Y over change in X. Here, you're seeing the average spread in Y over the average spread in X, and this would be the case when (R) is one.

Let me write that down; this would be the case if (R) is equal to one. What if (R) were equal to negative one? It would look like this; that would be our line if we had a perfect negative correlation. Now, what if (R) were zero? Then your slope would be zero, and your line would just be this line (Y = \text{mean of } Y), so you'd just go through that right over there.

But now let's think about this scenario. In this scenario, our (R) is (0.946), so we have a fairly strong correlation. This is pretty close to one. So if you were to take (0.946) and multiply it by this ratio, if you were to move forward in X by the standard deviation in X, for this case, how much would you move up in Y? Well, you would move up (R) times the standard deviation of Y.

As we said, if (R) was one, you would get all the way up to this perfect correlation line, but here it's (0.946), so you would get up about 95% of the way to that. Our line, without even looking at the equation, is going to look something like this, which we can see is a pretty good fit for those points.

I'm not proving it here in this video, but now that we have an intuition for these things, hopefully, you appreciate this isn't just coming out of nowhere. It's some strange formula; it actually makes intuitive sense. Let's calculate it for this particular set of data.

(m) is going to be equal to (R (0.946) \times \frac{\text{sample standard deviation of Y} (2.60)}{\text{sample standard deviation of X} (0.816)}). We can get our calculator out to calculate that.

So we have (0.946 \times 2.60) divided by (0.816), and it gets us to (2.50). Let's just round to the nearest hundredth for simplicity here, so this is approximately equal to (2.50).

How do we figure out the Y-intercept? Well, remember we go through this point. So, we're going to have (2.50 \times (\text{X mean})). Our X mean is (2), times (2.50) plus (b) is going to be equal to our Y mean. Our Y mean, we see right over here, is (3).

So what do we get? We get (3 = 5 + b). So what is (b)? Well, if you subtract five from both sides, you get (b = -2).

And so there you have it, the equation for our regression line. We deserve a little bit of a drum roll here! We would say (\hat{Y} = 2.50X - 2), and we are done.

More Articles

View All
One of the BEST way to save on taxes: What is a 401k
What’s up you guys, it’s Graham here. So, due to popular demand from a video I made about a week ago about why you should open up a Roth IRA, I’m going to make this video to share with you guys one of the best ways to reduce your taxable income and one of…
Dividing rational expressions: unknown expression | High School Math | Khan Academy
We’re told the following equation is true for all real values of Y for which the expression on the left is defined, and D is a polynomial expression. They have this equation here; what is D? All right, so essentially what they’re saying is they don’t wan…
Doc Brown "Loved Himself Some Einstein" | StarTalk
Einstein always kind of, uh, amazes me. And it was he amazes us all, by the way. Yes, yeah, and he was just a clerk in the patent Department. Yeah, nobody knew, you know, but he’s going looking at this, and there’s a railroad station. And he spent a lot …
The life cycle of a cup of coffee - A.J. Jacobs
How many people does it take to make a cup of coffee? For many of us, all it takes is a short walk and a quick pour. But this simple staple is the result of a globe-spanning process whose cost and complexity are far greater than you might imagine. It beg…
How the Trump Election and Social Media Externalized America’s Dormant Hate | Oliver Luckett
If you look at any of the kind of countercultural theorists that came out of the ‘60s at Berkeley, the Neil Postman’s, the Theodore Roszak’s, they kind of fundamentally, even into the talking heads, they kind of fundamentally they meant something to me wh…
Searching for Bullwinkle | Port Protection
Where are you going to go, Gary? Uh, we’re going to go and see if we can find Bow Winkle. You’ll probably hear them come through the brush or hear them walking in the muskeg before you see one, right? And call them in like a cowboy, you know. Really? Ye…