2

R-squared (coefficient of determination) is usually used to assess the goodness of fit of a regression model to the data. Here, I provide two simple datasets that I think their best-fit lines are equally good, but they got two different r-squared values.

x1 = [1,2,3]
y1 = [1,2,3.5]
x2 = [1,2,3]
y2 = [2,4,6.5]

The best fit line to x1,y1 got r2=0.9868, and the best fit line to x2,y2 got r2=0.9959. While the r-squared values are different for these two best-fit lines, the residuals for different points are exactly the same for them: [-0.083,0.167,-0.083]. I think these two lines are equally good in fitting their respective data, while they get different r-squared values. What is wrong with my intuition about coefficient of determination.

Hossein
  • 3,170
  • 1
  • 16
  • 32
  • 1
    Not an answer but a hint: have you checked the formula for $R^2$? – Lucas Farias Jun 02 '17 at 12:26
  • Possible duplicate of [Is $R^2$ useful or dangerous?](https://stats.stackexchange.com/questions/13314/is-r2-useful-or-dangerous) – Tim Jun 02 '17 at 13:17
  • 2
    Nobody said it is perfect, it is actually far from perfect. – Tim Jun 02 '17 at 13:17
  • @lucasfariaslf Yes I know the formula! I just don't understand why this is a perfect measure for goodness of fit. – Hossein Jun 02 '17 at 13:18
  • @Tim Thanks. So, one of the reasons of being far from perfect is that I mentioned in the problem? – Hossein Jun 02 '17 at 13:19
  • 1
    No, the reason why your examples differ is that they are not equivalent (!) and lead to different models as noted by @dbwilson. Notice that if you took `y2 = x1 * 2` than you'd get the same $R^2$. – Tim Jun 02 '17 at 13:34

2 Answers2

3

The residuals only enter the numerator of the $R^2$ formula $$ R^2=1-\frac{SSR}{TSS} $$ so that $R^2$ basically measures the residual variation relative to to the variation of the dependent variable. While the first is the same in your two datasets, the second are not.

Christoph Hanck
  • 25,948
  • 3
  • 57
  • 106
  • Yes, you are right. But I mean these two models are equally good, so R2 cannot be treated as a perfect measure of the goodness of fit. – Hossein Jun 02 '17 at 12:21
  • 3
    It depends on what you mean by perfect, but it does what its definition says it does - measure the *fraction* of variation in the data explained by the regression. One may very well argue that this is a sensible goal for a measure of goodness of fit, because it certainly is more difficult for a regression to achieve residuals of a given size when there is more variation in the data than when there is less. For example, the absolute size of "mistakes" of a regression will tend to be larger when explaining GDP (trillions of dollars) than houshold income (thousands of dollars). – Christoph Hanck Jun 02 '17 at 12:27
3

What makes you think these models are equally good? If you plot the data, you will see that the second model has a regression line that is closer to the data than the first. Y2 is not simply Y1 doubled, as that would be 2, 4, 7. Y2 is closer to linear than Y1. If you convert Y1 and Y2 to z-scores you will see that they are not equal.

dbwilson
  • 1,543
  • 7
  • 10