# Simple linear regression: R2 not equal to squared Pearson coefficient

The R2 of a simple linear regression model is the squared Pearson correlation coefficient (r) between the observations and the fitted values.

Isn't the above in contradiction with the fact that the R2 of a simple linear regression model is negative when the model fits the data worse than a horizontal line? That is, when the model predictions do not follow the trend of the data, as shown in the "wrong model" case below? In that case, the R2 is clearly not equal to the squared Pearson coefficient (nor to the square of anything), since it is negative.

Also, the $$r=-0.96$$ in the "wrong model" case below is misleading to me. Without looking at the plot, I would have interpreted it as an indication of a strong negative correlation (like the first plot, but going downward), whereas we can see that there is no correlation at all.

Any tips? Am I missing something?

EDIT according to this discussion, the above is possible if the model is constrained, which seems to answer part of my question. The $$r=-0.96$$ in the third plot is still misleading to me though.

Notes:

1. In the baseline case, r is technically undefined as the standard deviation is null. But clearly, if a variable is constant, it cannot be correlated with any other variable.
2. The definition of the R2 I am using is:
my_r2 = function(y,y_hat){
1 - sum((y-y_hat)^2)/sum((y-mean(y))^2)
}


For Pearson, I am using R's cor() function with the default arguments.

• "Simple linear regression" always includes an intercept. Such a model can never have an $R^2$ less than zero.
– whuber
May 25, 2021 at 17:00
• Yes, except if the model is "constrained", i.e., if its parameters (intercept and/or slope) are specified by hand instead of being fitted via OLS (see the discussion linked above). The other case when the $R^2$ can be negative is when the adjusted $R^2$ is used. May 25, 2021 at 17:49
• Sure: when you change the meaning of "simple linear regression" or the meaning of "R^2," standard results no longer hold! These issues are extensively discussed elsewhere on CV: see Adjusted R and negative R square.
– whuber
May 25, 2021 at 18:26
• Yes yes, I agree! May 25, 2021 at 18:30