What is the correct formula to compute R-squared? I'm completely confused about how to calculate R-squared for given lists of predicted and actual values.
As an example, assume that my predicted values are:  [3, 8, 10, 17, 24, 27] and my actual values are [2, 8, 10, 13, 18, 20].
According to wikipedia, I do the following:

*

*get the mean of the actual values (y-bar) = 14.8333

*compute the residual sum of squares (RSS).  For each pair of values, I'm getting the difference, squaring it, and summing the results.  i.e. (3-2)^2 + (8-8)^2 + (10-10)^2 and so on.  For my data this is 102.

*Compute the total sum of squares (TSS).  For each actual value, subtract it from the mean of the actual values, square the result, and sum all of these.  i.e. (2-14.833)^2 + (8-14.833)^2 and so on.  So TSS = 220.83333.

*R^2 = 1 - RSS/TSS = .53811

Contrast this method with one described here, which says I also need to be using the average of the predicted values, as well as what Excel gives using the RSQ formula (.9729).
Am I doing something wrong above?  Which is the correct formula/method to use?

There are multiple ways of calculating $R^2$ that are equivalent for ordinary least squares linear regression but are not equal in other circumstances.
I like $R^2=1-\frac{
SSRes
}{
SSTotal
}$, for reasons I discuss here. (Fair warning: this is not an introductory topic.)
However, some people like $R^2=(corr(y,\hat y))^2$. That appears to be the formula used in Excel.
If you fit by ordinary least squares, these two equations will be equal. If you do not fit by ordinary least squares, the two need not be equal.
The disagreement comes from the fact that your predictions are not great predictions of the true values, hence the low value of $R^2$ calculated the way I prefer. However, there is a solid linear relationship between the two, hence the high correlation.
As for what equation you should use to calculate your quantity of interest, that depends on what you find interesting! Both of these equations can give useful information, depending on what you want to know.
