MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Mathematica calculates RSquared wrongly?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112785] Re: Mathematica calculates RSquared wrongly?
  • From: Lawrence Teo <lawrenceteo at yahoo.com>
  • Date: Thu, 30 Sep 2010 04:52:37 -0400 (EDT)
  • References: <i7seru$pt5$1@smc.vnet.net>

With reference to the following statement,

> This is as designed. For nonlinear models, the corrected (i.e. with the
> mean subtracted out) sum of squares is sometimes used. This is
> consistent with comparing to a constant model, but most nonlinear models
> do not include a constant in an additive way. For this reason,
> NonlinearModelFit uses the uncorrected (i.e. without subtracting out the
> mean) sum of squares.

Is this the standard practice in mathematics world?
It seems to me that this takes away the common comparison ground
between linear and nonlinear regression.

I always get unrealistically high R^2 (>0.9) from NonlinearModelFit
function, even though the fit might be awfully off.
This makes me think if the so called uncorrected R^2 is right.

Any explanation? Thanks

PC


On Sep 28, 6:09 pm, Darren Glosemeyer <darr... at wolfram.com> wrote:
>   On 9/27/2010 4:47 AM, Lawrence Teo wrote:
>
>
>
> > sbbBN = {{-0.582258428`, 0.49531889`}, {-2.475512593`,
> >      0.751434565`}, {-1.508540016`, 0.571212292`}, {2.004747546`,
> >      0.187621117`}, {1.139972167`, 0.297735572`}, {-0.724053077`,
> >      0.457858443`}, {-0.830992757`, 0.313642502`}, {-3.830561204`=
,
> >      0.81639874`}, {-2.357296433`, 0.804397821`}, {0.986610836`,
> >      0.221932888`}, {-0.513640368`, 0.704999208`}, {-1.508540016`=
,
> >      0.798426867`}};
>
> > nlm = NonlinearModelFit[sbbBN, a*x^2 + b*x + c, {a, b, c}, x]
> > nlm["RSquared"]
>
> > The RSquared by Mathematica is 0.963173
> > Meanwhile, Excel and manual hand calculation show that R^2 should be
> > equal to 0.7622.
>
> > Is Mathematica wrong? Thanks!
>
> This is as designed. For nonlinear models, the corrected (i.e. with the
> mean subtracted out) sum of squares is sometimes used. This is
> consistent with comparing to a constant model, but most nonlinear models
> do not include a constant in an additive way. For this reason,
> NonlinearModelFit uses the uncorrected (i.e. without subtracting out the
> mean) sum of squares.
>
> Because the model you are using is a linear model, you could instead use
> LinearModelFit, which uses corrected sums of squares if a constant term
> is present and assumes a constant term is present unless it is told
> otherwise.
>
> In[1]:= sbbBN = {{-0.582258428`, 0.49531889`}, {-2.475512593`,
>              0.751434565`}, {-1.508540016`, 0.571212292`}, =
{2.004747546`,
>              0.187621117`}, {1.139972167`, 0.297735572`}, {=
-0.724053077`,
>              0.457858443`}, {-0.830992757`, 0.313642502`}, =
{-3.830561204`,
>              0.81639874`}, {-2.357296433`, 0.804397821`}, {=
0.986610836`,
>              0.221932888`}, {-0.513640368`, 0.704999208`}, =
{-1.508540016`,
>              0.798426867`}};
>
> In[2]:= nlm = NonlinearModelFit[sbbBN, a*x^2 + b*x + c, {a, b, c}, x]=
;
>
> In[3]:= nlm["RSquared"]
>
> Out[3]= 0.963173
>
> In[4]:= lm = LinearModelFit[sbbBN, {x, x^2}, x];
>
> In[5]:= lm["RSquared"]
>
> Out[5]= 0.762242
>
> Darren Glosemeyer
> Wolfram Research



  • Prev by Date: Re: Creating a Grid with square cells
  • Next by Date: Re: Root Finding Methods Gaurenteed to Find All Root Between (xmin, xmax)
  • Previous by thread: Re: Mathematica calculates RSquared wrongly?
  • Next by thread: RootSearch issue