Written and maintained by CASRAI Editorial Board
Last updated
The coefficient of determination, written R² and read “R-squared,” is calculated as R² = 1 − SSres / SStot: one minus the squared prediction errors of your model, divided by the squared deviations of the outcome from its own mean. This guide gives the formula with every symbol explained, a five-point worked example with the arithmetic shown, the case where R² turns out negative, how to report it in APA style, and one-line calculations in Excel, R and Python. For how to judge what a given value means in a results section, see CASRAI’s companion guide, how to interpret R-squared.
What is the coefficient of determination?
The coefficient of determination is the fraction of the total variability in the response (the outcome variable) that is accounted for by a model. The NIST/SEMATECH e-Handbook of Statistical Methods describes R² in its model-validation chapter as the fraction of the total variability in the response that is accounted for by the model. A value of 0.60 therefore means the model accounts for 60% of the variability of the outcome in the data used to compute it; the other 40% is left in the residuals. It is a property of one model fitted to one data set, not a property of the variables in general.
Coefficient of determination formula (SSres and SStot)
The general textbook definition is:
R² = 1 − SSres / SStot
- yi: the observed value of the outcome for observation i.
- fi (also written ŷi): the value the model predicts for observation i.
- ȳ (y-bar): the mean of all observed y values.
- SSres = Σ(yi − fi)²: the residual sum of squares, the part of the variation the model leaves unexplained.
- SStot = Σ(yi − ȳ)²: the total sum of squares, the variation of the outcome around its own mean, which is what a model that always predicted the mean would leave unexplained.
Read it as a comparison: SSres/SStot is the share of variation left over relative to the “just predict the mean” baseline, and R² is what remains after subtracting that share from one. In simple linear regression (one predictor, with an intercept) R² is also the square of the Pearson correlation r between x and y; see CASRAI’s correlation formula guide for r itself. That shortcut does not hold outside that setting, so the SS definition above is the one to rely on.
Coefficient of determination example: worked arithmetic
Five observations: x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5. Fit the least-squares line.
- Means: x̄ = 3 and ȳ = 4.
- Slope: Sxy = Σ(x − x̄)(y − ȳ) = (−2)(−2) + (−1)(0) + (0)(1) + (1)(0) + (2)(1) = 6. Sxx = 4 + 1 + 0 + 1 + 4 = 10. Slope b = 6/10 = 0.6.
- Intercept: a = ȳ − b·x̄ = 4 − 0.6 × 3 = 2.2. The fitted line is f = 2.2 + 0.6x.
- SStot: (2−4)² + (4−4)² + (5−4)² + (4−4)² + (5−4)² = 4 + 0 + 1 + 0 + 1 = 6.
- SSres: the fitted values are 2.8, 3.4, 4.0, 4.6, 5.2, so the residuals are −0.8, 0.6, 1.0, −0.6, −0.2. Squared: 0.64 + 0.36 + 1.00 + 0.36 + 0.04 = 2.4.
- R² = 1 − 2.4/6 = 1 − 0.4 = 0.60.
Check with the correlation route: r = Sxy / √(Sxx · SStot) = 6 / √(10 × 6) = 0.7746, and 0.7746² = 0.60. The two agree because this is simple linear regression with an intercept.
Can R-squared be negative?
Yes, when the predictions are not the least-squares line fitted to those same data, or when the model has no intercept. Using the same five points, force a line through the origin, f = bx. The best slope for that constraint is b = Σxy / Σx² = 66/55 = 1.2, giving fitted values 1.2, 2.4, 3.6, 4.8, 6.0 and residuals 0.8, 1.6, 1.4, −0.8, −1.0. Then SSres = 0.64 + 2.56 + 1.96 + 0.64 + 1.00 = 6.8, and R² = 1 − 6.8/6 = −0.13. A negative value says this model fits the data worse than simply predicting the mean of y, which has SSres = SStot = 6. The least-squares line with an intercept, by contrast, cannot do worse than the mean-only baseline, so the negative result comes from the constraint on the model, not from an arithmetic mistake.
Interpretation: what the result means
| R² value | What it says (from the formula) |
|---|---|
| 1 | SSres = 0: the model predicts every observed value exactly. |
| Between 0 and 1 | The model accounts for that fraction of the variability in the outcome; the rest remains in the residuals. |
| 0 | SSres = SStot: the model does no better than always predicting the mean. |
| Below 0 | SSres > SStot: the model does worse than predicting the mean. |
The table deliberately gives no “good” or “bad” cut-offs, because the formula does not supply any. What counts as a worthwhile R² depends on the field and the question; the guide on interpreting R-squared covers that judgment. To compare models with different numbers of predictors, see adjusted R-squared vs R-squared.
Assumptions and common mistakes
- A high R² does not prove the model fits. NIST states that a high R² value does not guarantee the model fits the data well, and describes numerical measures such as R² as useful but usually to a lesser degree than graphical methods. Its primary tool for checking a model is graphical residual analysis, so plot the residuals before relying on the number.
- R² = r² only in simple linear regression with an intercept. With several predictors there is no single r to square, and the SS formula is the definition to use.
- Do not drop the intercept casually. As the worked example shows, a no-intercept fit can produce a negative R² under this definition.
- It describes the sample used. The value is computed from the observed data and the model’s predictions on them; it is not by itself evidence about new data.
- It says nothing about causation. It measures how much variation is accounted for, not why.
How to report R-squared in APA style
The APA Style numbers and statistics guide (7th edition) sets three formatting rules that apply: statistical symbols are italicised, so the R in R² is italic; a zero is not used before the decimal for statistics that cannot exceed 1, so write .60 rather than 0.60; and correlations and proportions are reported to two decimal places. Standard symbols such as M, SD, F, t and p do not need to be defined.
For the example above, a reporting sentence is: “The model accounted for 60% of the variance in the outcome, R² = .60.” Because a negative R² is possible under the definition above, report it as computed (for example R² = −.13) and say which model produced it.
How to calculate it in Excel, R or Python
Excel
=RSQ(known_y's, known_x's)
=1 - SUMXMY2(y_range, fitted_range) / DEVSQ(y_range)
The first formula is the squared Pearson correlation, which equals R² for simple linear regression with an intercept; the second is the general SS definition for any set of predictions. For the example data, both return 0.6 when fitted_range holds 2.8, 3.4, 4.0, 4.6, 5.2.
R
x <- c(1,2,3,4,5); y <- c(2,4,5,4,5)
fit <- lm(y ~ x)
summary(fit)$r.squared # 0.6
1 - sum(resid(fit)^2) / sum((y - mean(y))^2) # same value by the formula
Python
import numpy as np
from sklearn.metrics import r2_score
x = np.array([1,2,3,4,5]); y = np.array([2,4,5,4,5])
b, a = np.polyfit(x, y, 1) # slope 0.6, intercept 2.2
print(r2_score(y, a + b*x)) # 0.6
print(r2_score(y, 1.2*x)) # about -0.133 (line through the origin)
For a fuller walk-through of fitting the line itself, see the linear regression calculator guide.
Frequently asked questions
What is the coefficient of determination?
It is the fraction of the variability in the outcome that a model accounts for, calculated as 1 − SSres/SStot. In the worked example it is 0.60.
Is the coefficient of determination the same as r²?
Only in simple linear regression with an intercept, where R² equals the squared Pearson correlation. In other models use the SS definition.
What is the formula for R-squared?
R² = 1 − Σ(yi − fi)² / Σ(yi − ȳ)².
Does a high R-squared mean the model is correct?
No. NIST notes that a high R² does not guarantee a good fit and recommends residual plots as the primary check.
Sources
All links checked on 2026-10-29.
- NIST/SEMATECH e-Handbook of Statistical Methods, “Model validation”: https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd44.htm (read 2026-10-29). Source for the description of R² as a fraction of variability and for the caution that a high R² does not guarantee a good fit.
- American Psychological Association, APA Style Numbers and Statistics Guide (7th edition): https://apastyle.apa.org/instructional-aids/numbers-statistics-guide.pdf (read 2026-10-29). Source for the formatting rules in the reporting section.
- Wikipedia, “Coefficient of determination” (secondary reference for the SSres/SStot definition, the squared-correlation case and negative values): https://en.wikipedia.org/wiki/Coefficient_of_determination (read 2026-10-29).
- Microsoft Support, RSQ function: https://support.microsoft.com/en-us/office/rsq-function-d7161715-250d-4a01-b80d-a8364f2be08f (read 2026-10-29). Source for RSQ returning the squared Pearson correlation.








