In ordinary least squares linear regression, $R^2=1-\frac{SSRes}{SSTotal}$ is described as the “proportion of variance explained”. Does this apply to nonlinear regression, too?

  • $\begingroup$ I have mentioned $R^2$ for nonlinear regression on here a few times and want a question to which I can link in the future. $\endgroup$
    – Dave
    Nov 11, 2021 at 23:45

1 Answer 1



Let’s start by deriving $R^2$ in the linear case.


$y_i$ is observation $i$ of some response variable $Y$.

$\hat{y}_i$ is the value of $y_i$ predicted by the regression.

$\bar{y}$ is the average of all observations of the response variable.

$$ y_i-\bar{y} = (y_i - \hat{y_i} + \hat{y_i} - \bar{y}) = (y_i - \hat{y_i}) + (\hat{y_i} - \bar{y}) $$

$$( y_i-\bar{y})^2 = \Big[ (y_i - \hat{y_i}) + (\hat{y_i} - \bar{y}) \Big]^2 = (y_i - \hat{y_i})^2 + (\hat{y_i} - \bar{y})^2 + 2(y_i - \hat{y_i})(\hat{y_i} - \bar{y}) $$

$$SSTotal := \sum_i ( y_i-\bar{y})^2 = \sum_i(y_i - \hat{y_i})^2 + \sum_i(\hat{y_i} - \bar{y})^2 + 2\sum_i\Big[ (y_i - \hat{y_i})(\hat{y_i} - \bar{y}) \Big]$$

$$ :=SSRes + SSReg + Other $$

Divide through by the sample size $n$ (or $n-1$) to get variance estimates.

In OLS linear regression, $Other$ drops to zero. Consequently, all of the variance in $Y$ is accounted for by the residual variance (unexplained) and regression variance (explained). We, therefore, can describe the proportion of total variance explained by the regression, which would be the variance explained by the regression model $(SSReg/n)$ divided by the total variance $(SSTotal/n)$.

$$ \dfrac{SSReg/n}{SSTotal/n} $$$$= \dfrac{SSReg}{SSTotal} $$$$= \dfrac{SSTotal -SSRes-Other}{SSTotal} $$$$= 1-\dfrac{SSRes}{SSTotal} $$

That final line is a common definition of $R^2$ (and equivalent to other common definitions like squared correlation in the two-variable setting, and squared correlation between predictions and true $y$ values in a multiple linear regression that has several predictor variables (assuming an intercept parameter estimate)).

However, that relied on $Other =0$. When that is false, as it is in nonlinear regression, the formula is not so clean. There’s something contributing to the total variance besides the residual and regression variances, and the usual $R^2$ no longer means what it meant in OLS linear regression.

This does not invalidate $R^2$ as a performance metric in nonlinear regression, however. Aside from possible numerical funkiness that comes from doing math on a computer, minimizing mean squared error (MSE), which is common in regression, is equivalent to minimizing $SSRes$ or maximizing $R^2$, so if you were comfortable using MSE, you should be comfortable using $R^2$.

However, since $Other\ne 0$, it would be incorrect to interpret $R^2=1-\dfrac{SSRes}{SSTotal}$ as the proportion of variance explained.

(Why we don’t seek to maximize $SSReg$ instead of minimizing $SSRes$ is the subject of another question by someone with a username that might look familiar, and I do believe the question here to be somewhat different.)

  • $\begingroup$ Uh, it's probably more a reflection of my being woolly headed right now than any problem with your post. I wouldn't panic to fix what's probably a non-problem! $\endgroup$
    – Glen_b
    Nov 12, 2021 at 0:41
  • $\begingroup$ I would add that "variance explained" is in the sample, not in a target population (i.e. $R^2$ does not estimate some $\rho^2$ without some serious assumptions about the distribution of regressors and regressands in the population). $\endgroup$
    – Alexis
    Mar 2, 2022 at 19:52
  • $\begingroup$ @Alexis I would be quite interested in reading an answer about that topic. $\endgroup$
    – Dave
    Apr 1, 2022 at 2:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.