Re: Problem with Fit
- To: mathgroup at smc.vnet.net
- Subject: [mg17363] Re: [mg17304] Problem with Fit
- From: David Withoff <withoff>
- Date: Mon, 3 May 1999 01:46:00 -0400
- Sender: owner-wri-mathgroup at wolfram.com
> I have experienced what appears to be an underflow or overflow problem > when using Fit. I fitted a quadratic {1,x,x^2} to a set of 26 data > points where the x-value was in the range 0 to 25000 and the y-value > was in the range 0 to 40; the results were as expected. I then tried > fitting a cubic {1,x,x^2,x^3} and the results were much worse, with > a larger RMS error than the quadratic. Trying higher powers such as > {1,x,x^2,x^4} and {1,x,x^2,x^5} gave increasingly poor fits. > > I then repeated the process but with all the x-values divided by 1000, > i.e. in the range 0 to 25. This time everything worked correctly and > the cubic fit was significantly better than the quadratic. There had > been no warnings or error messages with the original values, the only > indication of the problem being the very poor fit. > > Is this a known problem? Is it reasonable to expect Mathematica to be > able to issue a warning that something is amiss? The version I am using > is Mathematica 2.2 for SPARC; is there a later one for this platform? > > Richard. See the NumericalMath`PolynomialFit` package, especially the documentation for this package, which discusses the underlying mathematical issues and what to do about it. The general problem of polynomial fitting is also occasionally used in numerical analysis classes to illustrate numerical instability. The traditional solution to the numerical stability problem is to scale the data (as you mentioned), which usually solves most of the problem, and to use orthogonal polynomials, especially Chebyshev polynomials, rather than powers of the independent variable. The functions in the Statistics`LinearRegression` package will generate a warning message in these examples to warn you of the numerical problem, but for polynomials the recommended solution is the one used in the NumericalMath`PolynomialFit` package. The Fit function is a bare-bones linear regression function, and isn't designed to do any of the diagnostics that would detect this problem. The same problem can in principle come up when fitting any set of functions, not just polynomials, that aren't numerically linearly independent over the range of the data, but in practice the most common examples involve polynomial fitting, so that is the context in which this is usually discussed. Dave Withoff Wolfram Research