# RSquared: LinearModelFit vs NonlinearModelFit

I'm trying to understand the differences between LinearModelFit and NonlinearModelFit. One thing I notice is that the computation of "AdjustedRSquared" seems to be different, even when the model results are the same. Example:

data = {{1, 2}, {1, 2}, {2, 3}, {4, 6}, {5, 12}}
lm = LinearModelFit[data, x, x]
nlm = NonlinearModelFit[data, b + a*x, {a, b}, x]


gives the results

{{1,2},{1,2},{2,3},{4,6},{5,12}}
FittedModel[-0.712121+2.19697 x]
0.846521
FittedModel[-0.712121+2.19697 x]
0.929883


The returned FittedModels are exactly the same, however the "RSquared" differs. What exactly is going on here? Which one is a more accurate statement of $R^2$? Are my models functionally different in some way?

• I don't know the answer but here's some information about why R-square is an invalid metric for nonlinear fits. Commented Feb 3, 2015 at 3:34
• Wow, thank you. I actually had no idea about this, I'm pretty green when it comes to non-linear regressions! Commented Feb 3, 2015 at 14:10
• I wish Mathematica would throw this warning when you pull this data, similar to how they warn you not to do a t-test when your data sets are not normally distributed. Commented Feb 3, 2015 at 18:29

I mentioned in the comment above that there is a general belief that the R-squared value is not a suitable metric for nonlinear models but that leaves us with the question, what is NonlinearModelFit calculating? The font of all knowledge, Wikipedia, informs us that the definition of R squared is 1-ssres/sstot where ssres is the sum of squares of the residuals and sstot is the total sum of squares of the responses. Both of these numbers are obtained from the ANOVATable.
#["RSquared"]& /@{lm, nlm}

We can see here that LinearModelFit is calculating R squared using 1-8.28788/72 and NonlinearModelFit is using 1-8.28788/197. Therefore, we can conclude that the R-squared calculated using NonlinearModelFit utilizes the uncorrected Total sum of squares whereas LinearModelFit uses the generally accepted definition for this term.
• Just noticed this is actually mentioned in tutorial/StatisticalModelAnalysis. Commented Dec 3, 2015 at 14:10
• This has been raised internally a few times and it is as-designed. See the Possible Issues section of the NonlinearModelFit documentation. Commented Sep 11, 2020 at 0:55