## Little detail about R2 (or, don’t trust your software packages)

It is well-known that the coefficient of determination (R2) is not a kosher goodness-of-fit measure in nonlinear regression, but many people use it anyway. Everybody does it. How bad can it be?

I ran into this issue a while ago when I tried to do some statistics with *Mathematica*. Older versions of *Mathematica* don’t have a built-in function for R2. The designers probably knew that you shouldn’t use it anyway. But the NonlinearModelFit[] function introduced in version 7 does the calculation for you. What does it calculate? You look up the definition in Wikipedia and assume that it is what NonlinearModelFit[] calculates. Wikipedia knows everything, right?

Wrong. It turns out that there are at least 8 different definitions of R2 in nonlinear regression. The following paper catalogues these variants:

Kvalseth, T.O. (1985) Cautionary Note about R2. American Statistician, 39, 279-285.

So which version does *Mathematica* calculate? The technicians at Wolfram Research (apparently all PhDs) couldn’t give me an answer. After some experiments, I concluded that *Mathematica 7* arbitrarily uses definition #7, which is due to:

Marquardt, D.W. & Snee, R.D. (1874) Test statistics for mixture models. Technometrics, 16, 533-537.

Montgometry, D.C. & Peck, E.A. (1982) Introduction to linear regression analysis. John Wiley, NY.

Lesson: Don’t trust your software packages. Always check what it actually does. If you use *Mathematica*, here is a homework for you: what is the exact formula that *Mathematica* uses for its Bayesian Information Criterion (BIC) calculation? I asked Wolfram Research’s tech-support department this question. The technician sent me a link to Wikipedia. The problem is that, again, *Mathematica* does not use *that* definition. A different scaling factor is involved.