Re: Is there a bug in FIT?

*To*: mathgroup at smc.vnet.net*Subject*: [mg4402] Re: Is there a bug in FIT?*From*: rubin at msu.edu (Paul A. Rubin)*Date*: Fri, 19 Jul 1996 03:26:46 -0400*Organization*: Michigan State University*Sender*: owner-wri-mathgroup at wolfram.com

In article <4rq9ek$ld5 at dragonfly.wolfram.com>, welter at .ti.com (Jason Welter) wrote: ->I am trying to fit some data and have discovered that the ->FIT function does'nt work with the following data: -> ->data1 = {{1.42 10^13, -1.26}, {1.5 10^13, -1.3}, {1.63 10^13, -1.37}}; -> ->When I do: -> ->funcdata1 = Fit[data1,{1,x},x]; -> ->Show[{Plot[data1,{x,1.42 10^13,1.63 10^13}],ListPlot[data1]}, ->Prolog->AbsolutePointSize[16]] -> ->I get terrible results, but when I take the exponents out: -> ->data2 = {{1.42, -1.26}, {1.5, -1.3}, {1.63, -1.37}}; -> ->an I do: -> ->funcdata2 = Fit[data2,{1,x},x]; -> ->Show[{Plot[data2,{x,1.42,1.63}],ListPlot[data2]}, ->Prolog->AbsolutePointSize[16]] -> ->It fits it just fine. What is wrong? I suspect it's a problem with mathematical precision. The formula for the coefficient estimates is Inverse[ Transpose[ x ] . x ] . Transpose[ x ] . y, where x is the data matrix and y the vector of dependent values. In your case, the data matrix is {{1, 1.42 10^13}, {1, 1.5 10^13}, {1, 1.63 10^13}}, the first column (of 1's) corresponding to the constant term in your model. When you go to compute the inverse, the disparity in scaling of the columns causes rounding headaches. Now I computed the coefficients explicitly (as written above), using the formula above, with both versions of your data, and got correct answers both times. That's because Inverse[] coped pretty well with the conditioning problem. Fit, on the other hand, may not be using Inverse, but rather some other solution method which is more challenged by ill conditioning. Paul ************************************************************************** * Paul A. Rubin Phone: (517) 432-3509 * * Department of Management Fax: (517) 432-1111 * * Eli Broad Graduate School of Management Net: RUBIN at MSU.EDU * * Michigan State University * * East Lansing, MI 48824-1122 (USA) * ************************************************************************** Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. J. W. v. GOETHE ==== [MESSAGE SEPARATOR] ====