R² Calculator — Coefficient of Determination

R² Calculator — Coefficient of Determination

Growing AI Skill PRO

Enter Calculation

Formula

R2=1−SSresSStotwhere{SSres=∑(Actual y−Predicted y^)2SStot=∑(Actual y−y‾)2y‾=1n∑Actual y\begin{gathered} R^{2} = 1 - \frac{SS_{res}}{SS_{tot}} \\[1.5em] \text{where}\quad \left\{ \begin{aligned} SS_{res} &= \sum \left( {{\text{Actual } y}} - {{\text{Predicted } \hat{y}}} \right)^{2} \\ SS_{tot} &= \sum \left( {{\text{Actual } y}} - \bar{y} \right)^{2} \\ \bar{y} &= \frac{1}{n}\sum {{\text{Actual } y}} \end{aligned} \right. \end{gathered}
Usage stats

Advertisement

Results

Coefficient of Determination (R²)
0.9486
94.86% of variance explained
Data points (n) 4
Mean of actual 2.875
SS residual (SSres) 1.5
SS total (SStot) 29.1875

Report an error on this page

What Is the Coefficient of Determination (R²)?

The coefficient of determination, written \(R^{2}\), measures how well a model's predictions match the actual observed data. It is the proportion of the variance in the dependent variable that is explained by the model. \(R^{2}\) ranges from 1 (a perfect fit, where predictions exactly equal actual values) down through 0 (the model is no better than simply predicting the mean) and can even go negative when a model performs worse than the mean baseline.

Scatter plot with data points and a fitted regression line, showing how well the line explains the variance
R² measures how well a fitted line explains the variation in the data points.

How to Use This Calculator

Enter your list of actual observed values (y) and the matching list of predicted values (ŷ), each as comma-separated numbers in the same order. The calculator pairs them up, computes the mean of the actual values, then derives the residual sum of squares (SSres) and the total sum of squares (SStot) to return \(R^{2}\) and the percent of variance explained.

The Formula Explained

$$R^{2} = 1 - \frac{SS_{res}}{SS_{tot}}$$ Here \(SS_{res} = \sum (y_i - \hat{y}_i)^{2}\) captures the error left over after the model's predictions, while \(SS_{tot} = \sum (y_i - \bar{y})^{2}\) captures the total variability of the data around its own mean. Dividing one by the other tells you what fraction of variability the model failed to explain; subtracting from 1 gives the fraction it did explain.

Advertisement
Diagram comparing total variation around the mean versus residual variation around the fitted line
SStot is the spread around the mean; SSres is the leftover spread around the fitted line.

Worked Example

Actual = [3, −0.5, 2, 7], Predicted = [2.5, 0.0, 2, 8]. Mean of actual = 2.875. $$SS_{res} = 0.5^{2} + 0.5^{2} + 0^{2} + 1^{2} = 0.25 + 0.25 + 0 + 1 = 1.5$$ $$SS_{tot} = (0.125)^{2} + (3.375)^{2} + (0.875)^{2} + (4.125)^{2} \approx 0.0156 + 11.3906 + 0.7656 + 17.0156 = 29.1875$$ $$R^{2} = 1 - \frac{1.5}{29.1875} \approx 0.9486$$ so the model explains about 94.9% of the variance.

Interpreting Your R² Value

R² (the coefficient of determination) compares your model's squared errors with the squared errors of a simple baseline that always predicts the mean of the actual values: \(R^2 = 1 - SS_{res}/SS_{tot}\). Multiplied by 100, it is the share of variance in the actual values that the predictions account for.

R² What it indicates
1.0 Predictions match every actual value exactly (SSres = 0). 100% of the variance is explained.
0.9 About 90% of the variance is explained. This is a strong fit.
0.7 About 70% explained. This is a substantial fit, with noticeable unexplained scatter.
0.5 About half of the variance is explained and half is not.
0.3 About 30% explained. This is a weak fit, though it can still be meaningful in noisy fields.
0.0 The model does no better than predicting the mean every time (SSres = SStot).
Below 0 The model is worse than the mean baseline (SSres > SStot).

What counts as a good R²?

There is no universal threshold. In physical sciences and engineering, where measurements are controlled and relationships are close to deterministic, values above 0.9 are often expected. In social sciences, behavioral research, economics and many biological studies, outcomes are driven by many unmeasured factors, so an R² of 0.2 to 0.5 can still be useful. Judge the value against the norms of your field and the purpose of the model.

Important caveats

  • Not causation: a high R² shows that predictions track the data, not that the inputs cause the outcome.
  • Not bias: a model can have a high R² and still be systematically off in some ranges. Check residual plots.
  • Not overfitting: R² computed on the data used to fit a model tends to rise as predictors are added, even useless ones. Evaluate on held-out data where possible.
  • Adjusted R² penalizes extra predictors, so it is better for comparing models with different numbers of variables.
  • Negative values are possible whenever predictions come from something other than a least-squares fit to the same data, for example a model applied to new data.

R² Across Different Fit Scenarios

All four scenarios use the same actual values, y = 2, 4, 6, 8, 10. Their mean is \(\bar{y} = 30/5 = 6\), so \(SS_{tot} = (2-6)^2 + (4-6)^2 + (6-6)^2 + (8-6)^2 + (10-6)^2 = 16 + 4 + 0 + 4 + 16 = 40\) in every case. Only the predictions change.

Scenario Actual y Predicted ŷ SSres SStot R² Description
Perfect fit 2, 4, 6, 8, 10 2, 4, 6, 8, 10 0 40 1 Every residual is zero, so all variance is explained.
Good fit 2, 4, 6, 8, 10 3, 4, 6, 7, 10 2 40 0.95 Small errors of ±1 on two points. 95% of the variance is explained.
Mean only 2, 4, 6, 8, 10 6, 6, 6, 6, 6 40 40 0 Always predicting the mean gives exactly the baseline, so R² = 0.
Worse than the mean 2, 4, 6, 8, 10 10, 8, 6, 4, 2 160 40 -3 The predictions run in the opposite direction, so the errors are larger than the baseline's.

Arithmetic check

  • Good fit: residuals are -1, 0, 0, 1, 0, so \(SS_{res} = 1 + 0 + 0 + 1 + 0 = 2\) and \(R^2 = 1 - 2/40 = 0.95\).
  • Mean only: residuals are -4, -2, 0, 2, 4, so \(SS_{res} = 16 + 4 + 0 + 4 + 16 = 40\) and \(R^2 = 1 - 40/40 = 0\).
  • Worse than the mean: residuals are -8, -4, 0, 4, 8, so \(SS_{res} = 64 + 16 + 0 + 16 + 64 = 160\) and \(R^2 = 1 - 160/40 = -3\).
Advertisement

Key Terms and Symbols

R² (coefficient of determination)
The proportion of variance in the actual values that is accounted for by the predictions, \(R^2 = 1 - SS_{res}/SS_{tot}\). It is at most 1 and can be negative.
SSres (residual sum of squares)
The sum of squared differences between actual and predicted values, \(\sum (y - \hat{y})^2\). It measures the error the model leaves unexplained.
SStot (total sum of squares)
The sum of squared differences between each actual value and the mean, \(\sum (y - \bar{y})^2\). It measures the total variation in the data.
SSreg (explained or regression sum of squares)
The variation captured by the model, \(\sum (\hat{y} - \bar{y})^2\). For an ordinary least-squares fit with an intercept, \(SS_{tot} = SS_{reg} + SS_{res}\), so \(R^2 = SS_{reg}/SS_{tot}\). This identity does not hold for arbitrary predictions.
Residual
The error for one observation, \(y - \hat{y}\): actual minus predicted.
Mean of actual values (ȳ)
The average of the actual values, \(\bar{y} = \frac{1}{n}\sum y\). It is the baseline prediction that R² is measured against.
Predicted value (ŷ)
The value your model outputs for an observation.
Adjusted R²
A version of R² that penalizes the number of predictors p for a sample of size n: $$R^2_{adj} = 1 - (1 - R^2)\frac{n-1}{n-p-1}$$ It can fall when an added predictor does not improve the fit enough.
R² versus Pearson r
Pearson r measures the strength and direction (-1 to 1) of the linear association between two variables. In simple linear regression with an intercept, R² equals r². R² as calculated here compares any set of predictions to the actual values, so it can be negative, while r² cannot.

FAQ

Can R² be negative? Yes. If your predictions are worse than just guessing the mean every time, \(SS_{res}\) exceeds \(SS_{tot}\) and \(R^{2}\) becomes negative.

Does a high R² mean a good model? Not always — \(R^{2}\) can be inflated by overfitting or by adding irrelevant predictors. Always check it alongside residual plots and out-of-sample performance.

What is the difference between R² and correlation? For simple linear regression, \(R^{2}\) equals the square of the Pearson correlation coefficient (\(r\)) between actual and predicted values.

Last updated:

Most popular in Math and Statistics

View all Math and Statistics calculators