What is R-Squared?
R-squared (R²), also called the coefficient of determination, measures how well a model's predictions match the observed data. It ranges from 0 to 1 (often expressed as a percentage): an R² of 1 means the model explains all of the variability in the outcome, while 0 means it explains none. R² is one of the most widely used goodness-of-fit metrics in statistics, machine learning, and regression analysis.
How to use this calculator
Enter your actual observed values and your predicted (model) values as comma-separated lists. The lists should be the same length and in the same order. The calculator computes the residual sum of squares, the total sum of squares, and returns R² along with the percentage of variance explained.
The formula explained
R² is defined as:
$$R^{2} = 1 - \frac{SS_{res}}{SS_{tot}}$$
where \(SS_{res} = \sum (y_i - \hat{y}_i)^2\) is the sum of squared residuals (prediction errors), and \(SS_{tot} = \sum (y_i - \bar{y})^2\) is the total variance of the actual values around their mean \(\bar{y}\). A smaller residual error relative to total variance pushes R² closer to 1.
Worked example
Suppose the actual values are 3, 5, 7, 9, 11 (mean = 7) and the predictions are 2.8, 5.2, 6.9, 9.1, 10.8. The residuals are 0.2, −0.2, 0.1, −0.1, 0.2, so $$SS_{res} = 0.04+0.04+0.01+0.01+0.04 = 0.14.$$ The deviations from the mean are −4, −2, 0, 2, 4, so $$SS_{tot} = 16+4+0+4+16 = 40.$$ Therefore $$R^{2} = 1 - \frac{0.14}{40} = 0.9965$$ — the model explains about 99.65% of the variance.
FAQ
Can R² be negative? Yes. When using a model on new data (not fitted by ordinary least squares), predictions can be worse than simply using the mean, giving \(SS_{res} > SS_{tot}\) and a negative R².
Does a high R² mean a good model? Not always. A high R² can result from overfitting, and it does not confirm that the model assumptions are correct. Always inspect residuals and consider adjusted R² when comparing models with different numbers of predictors.
What is the difference between R² and correlation? For simple linear regression, R² equals the square of the Pearson correlation coefficient (r) between actual and predicted values.