# When is $R^2$ the same as Pearson's $r$ squared?

I am a bit confused about the relationship between Pearson's $r$ and the Coefficient of Determination $R^2$.

$$r = \frac{\sum\limits_{i = 1}^n (x_i - \overline x)(y_i - \overline y)}{\sqrt{\sum\limits_{i = 1}^n (x_i - \overline x)^2(y_i - \overline y)^2}}$$

$$R^2 = 1 - \frac{\sum\limits_{i = 1}^n (x_i - y_i)^2}{\sum\limits_{i = 1}^n (x_i - \overline x)^2}$$

Let $y$ be the prediction and $x$ be the actual values, and $\overline y$ and $\overline x$ their means.

Most explanations I have read says that $R^2$ can be derived by squaring the Pearson's $r$, and hence the name. However, using the formulas given above, then a squaring of $r$ does not equal $R^2$; at least for the data I have tried with.

Are the formulas wrong, or what is happening?

Wikipedia have a vague statement here: When an intercept is included, then $r^2$ is simply the square of the sample correlation coefficient (i.e., r).

• Your notation is quite confusing. $x$ is normally used for a regressor rather than for the actual values. Actual values are normally denoted $y$ which you use for fitted values. Fitted values are normally denoted $\hat y$. In addition, the first denominator is wrong. You should have a product of two roots, one of variance of $x$ and another of variance of $y$ (using your notation). Feb 7, 2018 at 16:37

Your confusion lies in the fact that this only works if $x_i = \hat{y_i}$, where $\hat{y_i}$ are the OLS predicted values for $y$ based on $x$ (i.e. linear regression of $y$ on $x$). Try running this regression and using $\hat{y}$ instead of $x$ and it'll work.

The short version is that for this to work, $x$ needs to satisfy several criteria (e.g. $\sum x_i(y_i - x_i) = 0$, etc), which are satisfied when $x_i = \hat{y_i}$.

• Sorry, you're right. I fixed it :) Feb 7, 2018 at 17:21

Even if your post is already some days old - for my own research I came across this post and about a very nice side that explains. So, maybe for others out there, have a look here: https://towardsdatascience.com/r%C2%B2-or-r%C2%B2-when-to-use-what-4968eee68ed3

BG Trieniti

• While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review May 24, 2022 at 0:39