Algorithm Search⌘K

Definitionintro

Coefficient of determination

Also called R-squared, adjusted R-squared.

The fraction of the variance of the response that the regression explains, one minus the residual sum of squares over the total sum of squares.

The coefficient of determination R2R^2 of a least squares fit with an intercept is the fraction of the variation of the response around its mean that the fitted values account for: R2=1−RSS/TSSR^2 = 1 - \mathrm{RSS}/\mathrm{TSS}. It lies between 0 and 1, equals the squared correlation between yy and y^\hat y, and in simple regression equals the squared correlation between xx and yy. Adding a predictor never lowers it, so the adjusted R2R^2 divides each sum of squares by its degrees of freedom. R2R^2 measures how much of the spread a linear fit removes in this sample. It does not measure whether the model is right, and a low value does not mean the slopes are 0. The test of that question is the F-test.

Definition

Let yy be the nn-vector of responses, XX an n×pn \times p design matrix of rank pp whose pp columns include the intercept column 1\mathbf 1, y^\hat y the ordinary least squares fitted values, e=y−y^e = y - \hat y and yˉ\bar y the mean of yy. Define

TSS=∑i=1n(yi−yˉ)2,RSS=∑i=1nei2,ESS=∑i=1n(y^i−yˉ)2.\mathrm{TSS} = \sum_{i=1}^n (y_i - \bar y)^2, \qquad \mathrm{RSS} = \sum_{i=1}^n e_i^2, \qquad \mathrm{ESS} = \sum_{i=1}^n (\hat y_i - \bar y)^2.

With an intercept, 1⊤e=0\mathbf 1^\top e = 0 and y^⊤e=0\hat y^\top e = 0, so TSS=ESS+RSS\mathrm{TSS} = \mathrm{ESS} + \mathrm{RSS}. Assume TSS>0\mathrm{TSS} > 0. The coefficient of determination is

R2=1−RSSTSS=ESSTSS.R^2 = 1 - \frac{\mathrm{RSS}}{\mathrm{TSS}} = \frac{\mathrm{ESS}}{\mathrm{TSS}}.

The adjusted coefficient replaces each sum of squares by its unbiased variance estimate under the model:

Rˉ2=1−RSS/(n−p)TSS/(n−1)=1−(1−R2)n−1n−p.\bar R^2 = 1 - \frac{\mathrm{RSS}/(n - p)}{\mathrm{TSS}/(n - 1)} = 1 - (1 - R^2)\frac{n - 1}{n - p}.

With k=p−1k = p - 1 slopes this is 1−(1−R2)(n−1)/(n−k−1)1 - (1 - R^2)(n - 1)/(n - k - 1), the form in many texts.

Facts. For a model with an intercept:

  1. 0≤R2≤10 \le R^2 \le 1. R2=1R^2 = 1 if and only if e=0e = 0; R2=0R^2 = 0 if and only if all fitted slopes are 0, so y^=yˉ1\hat y = \bar y\mathbf 1.
  2. R2=corr⁡(y,y^)2R^2 = \operatorname{corr}(y, \hat y)^2, the squared multiple correlation coefficient. In simple regression, R2=corr⁡(x,y)2R^2 = \operatorname{corr}(x, y)^2.
  3. Adding a column to XX never increases RSS (the old fit is still available), so R2R^2 never decreases. Rˉ2\bar R^2 increases if and only if the t statistic of the new coefficient satisfies ∣t∣>1|t| > 1, and it can be negative.
  4. The overall F statistic is a monotone function of R2R^2: F=R2/(p−1)(1−R2)/(n−p)F = \frac{R^2/(p - 1)}{(1 - R^2)/(n - p)}.
  5. If the errors are iid normal and all slopes are 0, R2R^2 has the Beta(p−12,n−p2)\big(\frac{p-1}{2}, \frac{n-p}{2}\big) law, with mean (p−1)/(n−1)(p - 1)/(n - 1). So pure noise gives a positive R2R^2 on average, and E[RSS/(n−p)]=E[TSS/(n−1)]=σ2E[\mathrm{RSS}/(n - p)] = E[\mathrm{TSS}/(n - 1)] = \sigma^2 is the reason Rˉ2\bar R^2 is centered near 0 in that case.

Examples and non-examples

Five points. For x=(1,2,3,4,5)x = (1, 2, 3, 4, 5) and y=(1,3,2,5,4)y = (1, 3, 2, 5, 4): yˉ=3\bar y = 3, TSS=10\mathrm{TSS} = 10, the fit is y^=0.6+0.8x\hat y = 0.6 + 0.8x, RSS=3.6\mathrm{RSS} = 3.6, so R2=0.64R^2 = 0.64, which is corr⁡(x,y)2=0.82\operatorname{corr}(x, y)^2 = 0.8^2. With n=5n = 5 and p=2p = 2, Rˉ2=1−0.36⋅4/3=0.52\bar R^2 = 1 - 0.36 \cdot 4/3 = 0.52.

A useless predictor. Add the column z=(2,−1,0,1,−2)z = (2, -1, 0, 1, -2), unrelated to the story. RSS drops to 3.5, so R2R^2 rises to 0.65, while Rˉ2=1−0.35⋅4/2=0.30\bar R^2 = 1 - 0.35 \cdot 4/2 = 0.30 falls.

Out-of-sample. The leave-one-out version, 1−PRESS/TSS1 - \mathrm{PRESS}/\mathrm{TSS} with PRESS=∑iei2/(1−hii)2\mathrm{PRESS} = \sum_i e_i^2/(1 - h_{ii})^2, is 1−9.057/10=0.0941 - 9.057/10 = 0.094 for the five points: most of the in-sample 0.64 does not survive prediction of new points. On a test set, 1−∑(yi−y^i)2/∑(yi−yˉ)21 - \sum(y_i - \hat y_i)^2/\sum(y_i - \bar y)^2 can be negative.

The same R2R^2 for four different pictures. In each of Anscombe's four data sets of 11 points, the fitted line is close to y^=3+0.5x\hat y = 3 + 0.5x and R2=0.667R^2 = 0.667 to three digits. One set is a linear cloud, one an exact parabola, one a line with one outlier, and one a vertical stack with a single far point that decides the slope. R2R^2 cannot tell them apart; a plot can.

Range dependence. In simple regression with slope b1b_1 and error variance σ2\sigma^2, the population value is b12Var⁡(x)/(b12Var⁡(x)+σ2)b_1^2\operatorname{Var}(x)/(b_1^2\operatorname{Var}(x) + \sigma^2). The same law, sampled over a wider range of xx, gives a larger R2R^2. Comparing R2R^2 across studies with different designs compares the designs as much as the models.

Non-example: a fit without an intercept. Fit y=(5,4,3,2,1)y = (5, 4, 3, 2, 1) on x=(1,2,3,4,5)x = (1, 2, 3, 4, 5) through the origin. The slope is 7/117/11 and RSS=360/11=32.73\mathrm{RSS} = 360/11 = 32.73, larger than TSS=10\mathrm{TSS} = 10, so 1−RSS/TSS=−2.271 - \mathrm{RSS}/\mathrm{TSS} = -2.27. The decomposition TSS=ESS+RSS\mathrm{TSS} = \mathrm{ESS} + \mathrm{RSS} fails because 1⊤e≠0\mathbf 1^\top e \ne 0. Many programs then report the uncentered 1−RSS/∑yi2=0.4051 - \mathrm{RSS}/\sum y_i^2 = 0.405, which compares the fit with the zero model, not with the mean, and is not comparable with an ordinary R2R^2. Kvålseth (1985) lists eight formulas that agree with an intercept and disagree without it.

Non-example: a large R2R^2 as proof of a good model. A curved relation fitted by a line, trending time series, or many predictors for few points all give a high R2R^2. A low R2R^2 with a clearly nonzero slope is common when the noise is large, and the slope can still be estimated well.

  • Overall F-test. Tests whether all slopes are 0. It is a function of R2R^2, nn and pp; R2R^2 alone has no level.
  • Partial R2R^2. (RSS0−RSS1)/RSS0(\mathrm{RSS}_0 - \mathrm{RSS}_1)/\mathrm{RSS}_0 for a nested pair of models: the fraction of the remaining variation that the added columns remove.
  • Rj2R_j^2 and the variance inflation factor. The R2R^2 of predictor jj regressed on the other predictors, with VIFj=1/(1−Rj2)\mathrm{VIF}_j = 1/(1 - R_j^2).
  • Pseudo-R2R^2. For a generalized linear model there is no unique analogue; McFadden's 1−log⁡L1/log⁡L01 - \log L_1/\log L_0 and the deviance-based versions are common, and they are not on the same scale as R2R^2.
  • Mean squared error. RSS/n\mathrm{RSS}/n; R2R^2 is one minus the ratio of the mean squared error of the fit to that of the constant predictor yˉ\bar y.
  • Cross-validation and information criteria. For model choice, out-of-sample error or the Akaike information criterion penalize size properly; Rˉ2\bar R^2 penalizes it weakly.

References

  1. Tarald O. Kvålseth, Cautionary note about R^2, The American Statistician 39(4), 1985, pp. 279 to 285, The whole paper (the competing formulas for R^2, their disagreement without an intercept, and the recommended definition 1 - RSS/TSS)
  2. F. J. Anscombe, Graphs in statistical analysis, The American Statistician 27(1), 1973, pp. 17 to 21, The four data sets with the same fitted line and the same correlation but very different shapes
  3. George A. F. Seber and Alan J. Lee, Linear Regression Analysis, second edition, Wiley, 2003, Chapter 4 (the sums of squares of the fit, the multiple correlation coefficient and the overall F-test)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/DCG94B/text.yaml