- Introduced by
- Karl Pearson
- Year
- 1896
- Type
- Goodness-of-fit metric
- Family
- Regression evaluation
What does it do?
The coefficient of determination, written R², is the proportion of variation in the dependent variable that a regression model accounts for.
It is computed as one minus the ratio of residual to total sum of squares, and it is one of the most widely reported goodness-of-fit summaries in regression.
The intuition behind the method
R² compares the model's errors with the errors of the simplest possible predictor, which always guesses the mean of the observations. If the model's squared errors are much smaller than the squared deviations from that mean, R² is close to 1. If the model is no better than the mean, R² is near 0. If the model's errors are larger than those of the mean predictor, R² is negative. Because it is a ratio of two sums of squares in the same units, R² has no units, so rescaling the target variable does not change it. For example, an R² of 0.85 means the model accounts for 85% of the variability in the target within the data used to fit it. Being unitless does not make R² comparable across different datasets, as discussed under pitfalls.
History
R² is now a standard summary in regression analysis, reported by most statistical software packages and used widely in econometrics, clinical research and machine learning.
When to use it
Use R² when you want a quick summary of how much of the variation in a continuous outcome a regression model accounts for, computed on the data used to fit the model or on a clearly stated evaluation set. It is a reasonable companion to residual plots for linear regression. Do not use it as the main criterion for choosing between models with different numbers of predictors, because it does not penalise added terms; adjusted R² and information criteria are designed for that comparison. The adjustment matters mainly when the number of predictors is large relative to the sample size, because R² overstates fit in that case. With large samples the correction is small, so cross-validation or a held-out error metric is a useful complement. R² is also a poor basis for judging nonlinear fits on its own, and it says nothing directly about prediction error on new observations.
Limitations and considerations
- In a least-squares model fitted to the same data, adding predictors cannot reduce R², so the statistic cannot by itself show that an added predictor improves the model
- Measures fit to the data used, not accuracy on new observations; applied to held-out data, the same formula can give much lower values and can be negative, because its denominator uses the mean of the evaluation observations and the model can then be worse than that mean
- Depends on how much the target varies: a model can have a low R² even when its absolute errors are small, if the target varies little
- Sensitive to extreme values, because squaring the residuals gives large errors a disproportionate influence on the sums
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Interpretable as the share of variation in the target accounted for by the model, when the model includes an intercept and is fitted by least squares to the same data
- Unitless, so the value does not change when the target is rescaled, and it can be read without knowing the target's units
- Simple to compute directly from the residuals and the mean of the observations
- Gives a direct comparison with the mean-only baseline, which is the natural reference model for a regression
Applications
- Econometrics: judging how much of the variation in an economic outcome, such as GDP growth, is accounted for by explanatory variables such as capital investment, labour, and technological factors
- Clinical research: checking how well a set of clinical measurements, such as blood pressure or cholesterol, accounts for a continuous patient outcome in a regression model
- Environmental science: summarising how closely a model reproduces historical temperature and precipitation records
- Machine learning: a quick check of regression baseline performance before comparing more complex algorithms
- Quality control: measuring how much of the variation in product yield is accounted for by process parameters such as temperature and pressure
How it works
How it works
Sum the squared differences between each observed value and the mean of all observed values. This gives the total variation in the target that the model is trying to explain.
Formula
SS_{tot} = \sum_{i=1}^{n} (y_i - \bar{y})^2Sum the squared differences between each observed value and the model's prediction for it. This is the variation left unexplained by the model.
Formula
SS_{res} = \sum_{i=1}^{n} (y_i - \hat{y}_i)^2Divide the residual sum of squares by the total sum of squares and subtract the result from one. Because both terms are sums of squares, the ratio is unitless, and it becomes negative when the residuals are larger than the deviations from the mean. The total sum of squares is measured around the mean of the observations, which presumes that the model includes an intercept. Software that fits a model without an intercept may report an uncentred R², which is computed differently and is not directly comparable with the value defined here.
Formula
R^2 = 1 - \frac{SS_{res}}{SS_{tot}}Common pitfalls
- Reading R² as evidence of causation; it describes how closely predictions match observations, not why they do
- Comparing R² across datasets with different target variance or different samples, since the same residual errors give different ratios when the total variation differs
- Over-reading a very high in-sample R² from a model with many parameters relative to the number of observations, which may reflect overfitting rather than a stable relationship
- Applying R² to nonlinear or non-least-squares fits without checking that the usual interpretation holds; for such models, the formula can give negative values
- Comparing R² values from panel or transformed-data models without checking how they were calculated. Software reports several variants, such as within R², the squared correlation between fitted and observed values, and RSS- or ESS-based versions, which are defined on different transformations of the data. State the variant and the transformation whenever R² is reported
Frequently asked questions
Can R² be negative?
Yes. A negative R² means the model's residuals are larger in total than the deviations of the observations from their mean, so the model performs worse than predicting the mean for every observation. This typically indicates a misspecified model (for example, a linear regression fitted to strongly nonlinear data), a predictor that was not fitted by least squares, or an incorrect calculation. A least-squares fit with an intercept, evaluated on its own training data, cannot produce a negative value.
Why does R² increase when I add more variables, even useless ones?
In a least-squares model fitted to the same data, adding any predictor cannot increase the residual sum of squares, so R² stays the same or rises slightly, even when the new predictor is pure noise. This is why R² alone cannot justify extra terms. Adjusted R² or information criteria such as AIC and BIC penalise the number of parameters and are better suited to comparing models of different size.
Is a high R² a guarantee that my model will predict well on new data?
No. A high R² on the training data can signal overfitting, particularly when the number of parameters is large relative to the number of observations. Validate the model on held-out data, for example with cross-validation, and assess prediction error on independent observations.
How does R² differ from the correlation coefficient r?
For simple linear regression with an intercept, R² equals the square of Pearson's correlation coefficient r between the predictor and the target. For multiple regression, R² is the squared correlation between the observed and fitted values, and it cannot be read as the square of a single correlation between the target and one predictor. For nonlinear models, the same interpretation does not hold.
Should I use R² to compare models fitted to different datasets?
Only with caution. R² depends on the variance of the target in each dataset: if one dataset has much higher variance, the same absolute errors produce a higher R², so the values are not directly comparable. Use cross-validation or a standardised error metric computed on a common evaluation set instead.
Related methods
Sources
Pearson, K. (1896). Mathematical contributions to the theory of evolution. Philosophical Transactions of the Royal Society A, 187, 253-318.
Open publication referencePearson, K. (1901). On lines and planes of closest fit to systems of points in space. The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science, 2(11), 559-572.
Open DOI referenceFisher, R. A. (1922). On the mathematical foundations of theoretical statistics. Philosophical Transactions of the Royal Society A, 222, 309-368.
Open DOI reference[Bruce_Ratner]_Statistical_and_Machine-Learning_Da(z-lib.org), p. 165
plm (R package reference manual), r.squared help page, p. 135