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
How to sell a $13,500,000 private jet!
I saw your advertisement for a Global Express. It’s your 2005. What can I tell you? How much are you wanting for it? 13 million 500,000. Are you doing this for a customer? No, we are currently… we have a small jet at the moment. We have a little L 35A.…
15 Things That Instantly Lower Status
You know, some of the things that you do are the adult version of giving somebody else the ick. Fortunately for you though, we’re here to help make sure that doesn’t happen. Some of these are strategic while others are just about being a basic human being…
Securing Lumber Stores (Deleted Scene) | Life Below Zero
It’s too hot out here. First t-shirt day of the year. Word is the river’s been moving upstream of me, so I’m expecting today, sometime today, maybe as late as early tomorrow morning. But not a lot of time to get the last finishing touches done here. It’s …
Re-Envisioning Reality - Tech+Art | Genius: Picasso
Almost my entire life has lived virtually on a screen, and what I’m looking for is a way to bring the digital experience put into physical form. I grew up in a place where, like, escapism was necessary. I was drawing and painting and programming and build…
$80,000,000 private jet tour!
Behind us is the future of corporate aviation. Let’s go inside and take a look. This is even bigger than the 6X. This is the standard bedroom with a king-size bed. But we have a larger one, which is a suite where you can have a desk, cabinet, and a seat …
The U.S. Interest Rate Problem Just Flipped (Jerome Powell Changes Stance)
If you’ve been paying attention to the stock market recently, you’ll have noticed it’s currently nose diving. It’s nothing crazy yet; it’s definitely not a stock market crash. But the S&P 500 is down around 5% since just last week. If you’re wondering…