Re: LinearModelFit vs. Fit with low precision/accuracy
- To: mathgroup at smc.vnet.net
- Subject: [mg99480] Re: [mg99438] LinearModelFit vs. Fit with low precision/accuracy
- From: Darren Glosemeyer <darreng at wolfram.com>
- Date: Wed, 6 May 2009 05:27:29 -0400 (EDT)
- References: <200905051003.GAA21938@smc.vnet.net>
andreas.kohlmajer at gmx.de wrote: > Hi all! > > I have some difficulties to understand the difference between > LinearModelFit and Fit with my low precision/accuracy data. I have 3 > different flow curves {flow [m=B3/h], back pressure [mbar]}: > > data = { > {{33.1, 0.19}, {37.5, 0.15}, {255.9, 4.79}, {390.8, 9.88}, {439.4, > 11.93}, {481, 13.77}, {558, 17.39}, {574.2, 18.15}, {601.3, > 19.5}, {665.4, 22.74}, {711.3, 25.26}, {726, 26.06}, {745, > 27.08}, {789.2, 29.39}, {798.4, 30.11}, {811.9, 30.7}, {825.8, > 31.74}, {847.6, 33.12}, {851.3, 33.34}}, > {{12.5, 0.06}, {37.5, 0.5}, {82, 1.18}, {100.8, 1.47}, {172.3, > 2.91}, {247.2, 5.11}, {257.8, 5.43}, {279.6, 6.13}, {353, > 8.73}, {433.5, 11.82}, {443.6, 11.82}, {545, 16.41}, {636.8, > 20.72}, {710.2, 24.03}, {814.6, 30.82}, {853.3, 32.95}, {924.6, > 38.44}}, > {{12.5, 0.05}, {17.7, 0.06}, {65, 1.08}, {115.9, 1.03}, {127.5, > 2.49}, {266.7, 4.85}, {282.1, 5.51}, {309.1, 6.2}, {369.2, > 8.52}, {373.8, 8.71}, {395.4, 9.49}, {418.1, 10.28}, {445.6, > 11.37}, {489.7, 13.15}, {494.9, 13.34}, {522, 14.25}, {539.4, > 15.25}, {606.5, 17.88}, {615.1, 18.65}, {677.5, 21.52}, {689, > 21.52}, {768.8, 26.41}, {838.1, 30.56}, {877.1, 33.07}, {943.7, > 37.58}} > }; > > The data is quite inaccurate, so I specified two different accuracies > for flow (whole digit) and back pressure (1 decimal): > > data[[All, All, 1]] = SetAccuracy[data[[All, All, 1]], 1]; > data[[All, All, 2]] = SetAccuracy[data[[All, All, 2]], 2]; > > The model is a simple parabola: > > model = {x, x^2}; > > The linear model fit is: > > lm = LinearModelFit[#, model, x] & /@ data > > The regular fit is: > > ft = Fit[#, model, x] & /@ data > > The linear model fit returns a low precision/accuracy constant, > whereas the regular fit returns a parabola fit with no valid digit for > any of the coefficients. > > Of course, the data is too inaccurate to calculate a sufficient fit, > but why do I see this difference between LinearModelFit and Fit? > There are a couple of differences (the differences do not completely address what you are seeing, but we'll get to that shortly). First, Fit uses code based on pseudo inverse, while LinearModelFit uses LeastSquares so slight differences in results may occur. Second, LinearModelFit includes a constant term by default while Fit does not. To fit a model with the same terms, you could either add the option IncludeConstantBasis->False to LinearModelFit or change model to {1, x, x^2} depending on whether you want a constant term or not. I think using WorkingPrecision or setting the precision on the data would be a better route if necessary, though it is not clear to me that setting the precision of accuracy is really useful in low precision/accuracy cases. Machine precision will be faster and generally give perfectly good results, as is the case with data given. That said, there does appear to be an issue with low accuracy cases which is causing the constant only results in LinearModelFit. I have made a change in the development kernel to address this and the fix should appear in a future version of Mathematica. Darren Glosemeyer Wolfram Research
- References:
- LinearModelFit vs. Fit with low precision/accuracy data
- From: andreas.kohlmajer@gmx.de
- LinearModelFit vs. Fit with low precision/accuracy data