MathGroup Archive 2005

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

Search the Archive

Re: A Problem with the NonlinearFit?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61770] Re: [mg61757] A Problem with the NonlinearFit?
  • From: Chris Chiasson <chris.chiasson at gmail.com>
  • Date: Sat, 29 Oct 2005 01:32:37 -0400 (EDT)
  • References: <200510280725.DAA08743@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I think both regressions are correct. The reason you get different
numbers is that a regression minimizes the total square error.
Minimizing the square error in the log space is not the same as
minimizing the square error in the non log space.

Does anyone have a kind of follow up or corollary to this? Eg, what do
people normally do in this situation?

Compare:
eqns[1]=a Exp[b x]\[Equal]y
dat[1]={{0,319.9},{1,196.7},{3,140.2},{7,99.0},{14,56.1},{31,32.8},{90,1.9}}
fit[1]=FindFit[dat[1],First@eqns[1],{a,b},x]
Plot[Evaluate[First@eqns[1]/.fit[1]],{x,Min[dat[1][[All,1]]],
    Max[dat[1][[All,1]]]},Epilog\[Rule]{Hue[0],Line[dat[1]]},
  PlotRange\[Rule]All]
assums=Flatten[{#>=0&/@{x,y,a},b<0}]
eqns[2]=Sort@FullSimplify[Thread[Log[eqns[1]],Equal],assums]
dat[2]={#1,Log[#2]}&@@@dat[1]
fit[2]=FindFit[dat[2],First@eqns[2],{a,b},x]
Plot[Evaluate[Exp[First@eqns[2]/.fit[2]]],{x,Min[dat[2][[All,1]]],
    Max[dat[2][[All,1]]]},Epilog\[Rule]{Hue[0],Line[{#1,Exp[#2]}&@@@dat[2]]},
  PlotRange\[Rule]All]
Total[Function[{x,y},Evaluate[(Subtract@@eqns[1])^2/.fit[1]]]@@@dat[1]]
Total[Function[{x,y},Evaluate[(Subtract@@eqns[1])^2/.fit[2]]]@@@dat[1]]
Total[Function[{x,y},Evaluate[(Subtract@@eqns[2])^2/.fit[1]]]@@@dat[2]]
Total[Function[{x,y},Evaluate[(Subtract@@eqns[2])^2/.fit[2]]]@@@dat[2]]

On 10/28/05, Axel Ligon <ligonap at web.de> wrote:
> Deas Sirs,
>
> concerning the NonlinearFit procedure I have a problem. I used the
> following inputs:
>
> A)
> *Raw datas {x, y}*
> dat1={{0,319.9},{1,196.7},{3,140.2},{7,99.0},{14,56.1},{31,32.8},{90,1.9}}
> FindFit[dat1,a*Exp[-b*x],{a,b},x]
>
> a ->280.376, b->0.175479
>
> <<Statistics`NonlinearFit`
> f=NonlinearFit[dat1,a*Exp[-b*x],x,{a,b}]
>
> 280.376 * Exp(-0.175479x)
>
> B)
> *Convert datas {x, ln[y]}*
> dat2={{0,5.7680},{1,5.2817},{3,4.9430},{7,4.5951},{14,4.0271},{31,3.4904},{90, 0.6419}}
> FindFit[dat2,-b*x+a,{a,b},x]
>
> a->5.18756, b->0.0518199
>
> <<Statistics`NonlinearFit`
> f=NonlinearFit[dat2,-b*x+a,x,{a,b}]
>
> 5.18756 - 0.0518199 x
>
> The difference between A) and B) is only the conversion of y to ln[y]
> and the equation y = a * exp(-b*x) to ln[y] = ln[a] - b*x. From this
> it follows that a = exp[ln[a]].
> But I get in A) 280.376 / -0.175479 and in B) 179.031 / -0.05182 !!
> Why do I get these error?? If I use Excel, I don't get these errors.
> Is it an error in the programming of Mathematica, or not???
>
> I'd be glad if you could help me.
>
> With best regards
>
> Axel Ligon
>
>
>


--
http://chrischiasson.com/contact/chris_chiasson


  • Prev by Date: Re: Integrate vs Nintegrate for impulsive functions
  • Next by Date: Re: ParallelIO (mathlink windows program) Help Please
  • Previous by thread: A Problem with the NonlinearFit?
  • Next by thread: Re: A Problem with the NonlinearFit?