If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

R-squared or coefficient of determination

In linear regression, r-squared (also called the coefficient of determination) is the proportion of variation in the response variable that is explained by the explanatory variable in the model. Created by Sal Khan.

Want to join the conversation?

• How do we know that the squared error of the line is always less than (or equal to) the variance in the y values?
• Regression line is usually the best fit for a given scatter plot, but if you draw the mean of Y that would just be a horizontal line in that plot, and definitely that horizontal line wouldn't be fit as good as the regression line. So the Total squared error from the mean (SE Y) would deinitely be greater than the total squared error from the regression line (SE Line). Therefore SE Line/ SE Y can never be greater than 1 and hence R^2 can't be negative. Hope that helps.
• Hello everyone. I have some troubles understanding the concepts explained in this video on a deeper level. I would like to discuss some things.
In this video Sal talks a lot about the "variation in y" and "how much of the variation in y is described". However, I found myself wondering what is really this variation in y, what does it describe? Why do we care about this number?
I've always thought that the variance (or variation) of something is important when that something has a central tendency, and points tend to scatter randomly around that centre. The variance helps you quantify how much those points scatter around.
Here, however, we have y's that are positively correlated to the x's, which means that if you pick higher and higher values for x, you also get higher and higher values for y. So, there is really no central tendency for the y values, and in fact, the values you calculate for the "mean_y" and the "variation in y" will vary depending on which x values you choose. If we take points that have higher x's, our mean_y will increase, and if we take points with a wider range in x, our "variation in y" will also increase! So it seems to me that this "variation in y" has really no meaning in this context - it's an arbitrary number that depends on which x values we happen to choose. So why would we care about how much this random number we calculate and call "variation in y" is and how much of it is "explained" - whatever that even means?

Now, I've managed to explain to myself what's been done here in a different way, and this kind of makes intuitive sense to me. Unlike the variation in y, the Standard Error is a much more significant concept in this context. It measures what's the error that one commits with their estimation of the relation between x and y (regression line).
The variation in y, as it was defined, measures the error from the mean_y. So, this is equivalent to the error that one commits if they fit the points with a horizontal line y = mean_y. Now that makes sense to me, it's what one would do if they had no better tools for fitting lines to points than saying "we want to fit a line to a bunch of points? Hey, why don't we just take a horizontal line that goes through the mean of the y values we have".
In fact, y = mean_y is the line of the form y = constant that minimizes the SE. So, it's the best line of its kind. Still, a constant line is the most basic model one could come up with, as a linear function, an exponential function, a quadratic function all can adapt better to points and have more "degrees of freedom" (more parameters to be played with) than a line y = constant. So, SE_y can be seen as the error that is committed by fitting points with the worst - or most basic - model available.
If we see things this way, SE_line / SE_y kind of measures how much of a better fit we have with our model compared to the most-basic model available.
Does that not make more intuitive sense?
• Yes, that was my question as well! I hope it gets answered soon.
• Why do we minimize r squared instead of r? I mean, why do we minimize the square distance instead of just the distance? Is it just for accuracy or something deeper?
• Why are we comparing Squared error (S.E. line) with total variation in y (S.E. y) ?
Thought it seems convincing and logical to compare it with S.E.y, my question is, S.E.y may not be perfectly absolute domain for S.E.line .
• Can we say that the higher the value of R2, the greater the probability the model is
correct?
and is the most important factor when comparing a model with any others is
to find the highest R2?
• Not necessarily. R2 only measures how well a line approximates points on a graph. It is NOT a probability value. How likely a model is correct depends on many things and is the subject of hypothesis testing (covered in future videos). It is possible (and common, even in science) that a linear model describes the data perfectly even though it is the wrong model for whatever process generated the data.
Say I am trying to model outdoor air temperature over time, but I only measure air temperatures once a day, and only during spring. If the data turns out linear (probably would not be), a best fit line could have a high R2, but the line would not describe 24h variation in temperature caused by night/day cycles. More importantly, the line would predict that temperature increases forever (since it was warming in spring, when we sampled), which clearly is not true, even under the most dire global warming predictions ; ). R2 only matters if you pick the right model and sample at the right resolution.
• Issue: Variation in x does not refer to the line. Solution: M and b provide the best match to variation in y using a straight line model. Since data is not on a line, a line is not a perfect explanation of the data or a perfect match to variation in y. R-squared is comparing how much of true variation is in fact explained by the best straight line provided by the regression model. If R-squared is very small then it indicates you should consider models other than straight lines.
• If R-squared is close to zero, a line may not be appropriate (if the data is non-linear), or the explanatory variable just doesn't do much explaining when it comes to the response variable (y-variable). In that case, you should consider adding another explanatory variable (multiple regression), or find a new explanatory variable altogether.
• This makes absolutely no sense at all. How does the mean of y (y_bar) subtracted from any given y represent an error? What does the average y (y_bar) represent? What if, as x increases, there IS an upward trend?

This would make sense if the y value was a constant, say 6. You could measure the total error by taking the difference of each measured y and the value 6. The average, at least to me, really does not represent anything. So, how can a measured value of y over the average of all measured y's represent an error of anything? If the measured y's were for the same x value, then a variation in y could be measured as an error. But if the y has a relationship with x such that it increases as x increases, how does y/y_bar represent error in any sense?

-----------------------------------------
For example:

You are given an unknown resistance. You decide to experimentally determine the resistance of the component by measuring its i-V (current, voltage) curve (response).

Given that X is voltage, and Y is current, you may measure something like this:

In an ideal case:
X = 10V, Y = 1Amp
X = 20V, Y = 2Amp
X = 30V, Y = 3Amp
If you plot this curve, there is quite obviously a linear relationship. And, if you are familiar with Ohm's relationship(LAW, if you like), we have the resistance = 10Ohms.

-- The point is, as Voltage increases, current increases as well for any constant resistance R. So, we have a positively sloping linear relationship.

So, from the ideal case above.
y_bar = 2 Amps.
So, given what we have in this video:
The total error associated with our measured values(current, Y), is given by:
(y1-y_bar)^2 + (y2-y_bar)^2 + (y3-y_bar)^2 = (1-2)^2 + (2-2)^2 + (3-2)^2 = 2

Given an ideal world, where the resistance was EXACTLY equal to 10Ohms, and we measured precisely the expected values of current needed to resolve this, how can we say that the measured data had a total error associated with our measured values of current equal to 2?
• You raised a number of points here, I'll try to address them all:

> "How does the mean of y (y_bar) subtracted from any given y represent an error?"

When we say "error" we're really meaning "deviation," specifically, deviation from the mean. Ybar is a measure of center, or a "typical" value, and the deviations of (Y - Ybar) can be used to give us some idea of the spread around that measure of center.

> "What does the average y (y_bar) represent?"

It represents the norm, or a "typical" y-value,

> "What if, as x increases, there IS an upward trend?"

That would be an indication of positive correlation between X and Y.

> "This would make sense if the y value was a constant, say 6. You could measure the total error by taking the difference of each measured y and the value 6."

I think this is where you may be going astray. If the y-value was a constant, like 6, there would be no variability, all the y-values would be 6. Just associate Ybar, the average, with this value of 6 that you conjecture.

The idea in correlation is to measure above average vs below average for both X and Y. Correlation is looking at when values are above/below average - meaning: higher than normal or lower than normal, and it is looking at this for both X and Y simultaneously. In a sense, it's asking the question "Are larger above-average Y-values associated with above-average X-values?" This is why we care about and need the average.

In your example with Ohms, you only calculated what we'd call the Sum of Squares for Y: SUM{ (Yi - Ybar)^2 }. This is close to the variance. You obtained a 2 (which is correct). And this IS a measure of variability for Y: not all of the Y-values are equal, so there is variability among the Y's! When we take X into account, we'd see that we have a deterministic relationship, but if we look at each variable alone, there are differences, and hence variability.
• I don't exactly see why we are comparing SEline to SEy. Why do we care about SEy here?
• The r-squared coefficient is the percentage of y-variation that the line "explained" by the line compared to how much the average y-explains. You could also think of it as how much closer the line is to any given point when compared to the average value of y. SEy is the total variation in y (sum of squared distances from the mean of y) and tells you the how much the data deviates from the mean of y. The variation in y gives you a baseline by which to judge how much better the best fit line fits the data compared to the y average.
• First of all, I feel this video is genius with the pictural description of the errors vs. mean and errors vs. regression line. However, I am slow, and I am lost at the following step: when we say that SE(Line) shows what is NOT explained by the regression line; and therefore SE(Line)/SE(y) = what % of variation that is not explained by the variation in x.

A few questions:

1. Why is the variation in x equivalent to the regression line? Is this just linguistics to say that the regression line is the result of independent variable x to obtain y, so the regression line describes the variation in x and its impact on y?

2. SE(Line) / SE(y) essentially is equivalent to: the errors of the regression (which are thus not explained by the regression) divided by the sum of the total regression. For that reason, we know what % is not explained by the regression, and then we can deduct what is explained by the regression. Is that the right way to think about it?