Lably
Skip to content

Coefficient of determination

Indicator for how well data points fit a line or curve

  • 20 min read
  • 5 chapters

Related on Lably

Through Statistics, Statistic and Prediction

There are several definitions of R2 that are only sometimes equivalent. In simple linear regression (which includes an intercept), r2 is simply the square of the sample correlation coefficient (r), between the observed outcomes and the observed predictor values. If additional regressors are included, R2 is the square of the coefficient of multiple correlation. In both such cases, the coefficient of determination is always smaller than 1 and usually greater than 0.

Cases where R2 is negative can arise when the predictions that are being compared to the corresponding outcomes have not been derived from a model-fitting procedure using those data. Even if a model-fitting procedure has been used, R2 may still be negative, for example when linear regression is conducted without including an intercept, or when a non-linear function is used to fit the data. In cases where negative values arise, the mean of the data provides a better fit to the outcomes than do the fitted function values, according to this particular criterion.

The coefficient of determination can be more intuitively informative than MAE, MAPE, MSE, and RMSE in regression analysis evaluation, as the former can be expressed as a percentage, whereas the latter measures have arbitrary ranges. It also proved more robust for poor fits compared to SMAPE on certain test datasets.

When evaluating the goodness-of-fit of simulated (Ypred) versus measured (Yobs) values, it is not appropriate to base this on the R2 of the linear regression (i.e., Yobs=m·Ypred + b). The R2 quantifies the degree of any linear correlation between Yobs and Ypred, while for the goodness-of-fit evaluation only one specific linear correlation should be taken into consideration: Yobs=1·Ypred + 0 (i.e., the 1:1 line).

Definitions

A data set has n values marked y1, ..., yn (collectively known as yi or as a vector y=[y1, ..., yn]T), each associated with a fitted (or modeled, or predicted) value f1, ..., fn (known as fi, or sometimes ŷi, as a vector f).

Define the residuals as ei=yi − fi (forming a vector e).

If y¯ is the mean of the observed data: y¯=1n∑i=1nyi then the variability of the data set can be measured with two sums of squares formulas:

  • The sum of squares of residuals, also called the residual sum of squares: SSres=∑i(yi−fi)2=∑iei2
  • The total sum of squares (proportional to the variance of the data): SStot=∑i(yi−y¯)2

The most general definition of the coefficient of determination is R2=1−SSresSStot

In the best case, the modeled values exactly match the observed values, which results in SSres=0 and R2=1. A baseline model, which always predicts y, will have R2=0.

Relation to unexplained variance

In a general form, R2 can be seen to be related to the fraction of variance unexplained (FVU), since the second term compares the unexplained variance (variance of the model's errors) with the total variance (of the data): R2=1−FVU

As explained variance

A larger value of R2 implies a more successful regression model. Suppose R2=0.49. This implies that 49% of the variability of the dependent variable in the data set has been accounted for, and the remaining 51% of the variability is still unaccounted for. For regression models, the regression sum of squares, also called the explained sum of squares, is defined as

SSreg=∑i(fi−y¯)2

In some cases, as in linear regression, the total sum of squares equals the sum of the two other sums of squares defined above:

SSres+SSreg=SStot

See Partitioning in the general OLS model for a derivation of this result for one case where the relation holds. When this relation does hold, the above definition of R2 is equivalent to

R2=SSregSStot=SSreg/nSStot/n

where n is the number of observations (cases) on the variables.

In this form R2 is expressed as the ratio of the explained variance (variance of the model's predictions, which is SSreg / n) to the total variance (sample variance of the dependent variable, which is SStot / n).

This partition of the sum of squares holds for instance when the model values ƒi have been obtained by linear regression. A milder sufficient condition reads as follows: The model has the form

fi=α^+β^qi

where the qi are arbitrary values that may or may not depend on i or on other free parameters (the common choice qi = xi is just one special case), and the coefficient estimates α^ and β^ are obtained by minimizing the residual sum of squares.

This set of conditions is an important one and it has a number of implications for the properties of the fitted residuals and the modelled values. In particular, under these conditions:

f¯=y¯.

As squared correlation coefficient

In linear least squares multiple regression (with fitted intercept and slope), R2 equals ρ2(y,f) the square of the Pearson correlation coefficient between the observed y and modeled (predicted) f data values of the dependent variable.

In a linear least squares regression with a single explanator (with fitted intercept and slope), this is also equal to ρ2(y,x) the squared Pearson correlation coefficient between the dependent variable y and explanatory variable x.

It should not be confused with the correlation coefficient between two explanatory variables, defined as

ρα^,β^=cov⁡(α^,β^)σα^σβ^,

where the covariance between two coefficient estimates, as well as their standard deviations, are obtained from the covariance matrix of the coefficient estimates, (XTX)−1.

Under more general modeling conditions, where the predicted values might be generated from a model different from linear least squares regression, an R2 value can be calculated as the square of the correlation coefficient between the original y and modeled f data values. In this case, the value is not directly a measure of how good the modeled values are, but rather a measure of how good a predictor might be constructed from the modeled values (by creating a revised predictor of the form α + βƒi). According to Everitt, this usage is specifically the definition of the term "coefficient of determination": the square of the correlation between two (general) variables.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Statistics and probability