Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## gnuplot-info

 [Gnuplot-info] wrong simple linear fit From: Eckard Specht - 2005-06-17 09:06:10 ```Hi@..., I'm not sure if my fit problem with gnuplot is an old hat. I have built a site that helps students to get results from physical experiments by the help of gnuplot. All is well but for a simple linear fit I get wrong parameters. My data are: 6.03e5 0.4 6.79e5 0.45 7.54e5 0.5 8.30e5 0.55 9.05e5 0.6 9.81e5 0.65 which are stored in a file 'lreg3.dat'. My gnuplot commands are: f(x) = a*x+b fit f(x) 'lreg3.dat' via a,b plot f(x), 'lreg3.dat' gnuplot comes up with a totally wrong regression line (i.e. a negative slope). If one scratches one data pair from list, the result is correct. I have read in 'help fit' that this misfit can occur if the magnitudes of both parameters a, b differ too much. This may be the case here. But a simple linear fit should always work. Or not? Is it true that the Marquardt-Levenberg algorithm is used for all fits? Must I provide 'good' starting values for a, b to get a correct result? This would be very inconvenient here. Thank you very much for your help/comments. Regards, -Eckard ```
 Re: [Gnuplot-info] wrong simple linear fit From: Hans-Bernhard Broeker - 2005-06-17 09:52:43 ```Eckard Specht wrote: > gnuplot comes up with a totally wrong regression line (i.e. a negative slope). > If one scratches one data pair from list, the result is correct. > > I have read in 'help fit' that this misfit can occur if the magnitudes of both > parameters a, b differ too much. This may be the case here. Not if the parameters are this different, the default startup values of 1.0 three orders of magnitude from the goal, and, which is the worst problem here, and the actual value for one of the fitted parameters (b) is zero, which makes it uncontrollable by the fit: fit m*x 'lreg3.dat' via m gives a very nice fit already: After 5 iterations the fit converged. final sum of squares of residuals : 2.48482e-007 rel. change during last iteration : -6.69962e-012 degrees of freedom (ndf) : 5 rms of residuals (stdfit) = sqrt(WSSR/ndf) : 0.000222927 variance of residuals (reduced chisquare) = WSSR/ndf : 4.96965e-008 Final set of parameters Asymptotic Standard Error ======================= ========================== m = 6.62853e-007 +/- 1.134e-010 (0.01711%) So the actual result is b=0, which means the magnitude ratio of the parameters is *infinite*. That will indeed throw off the fit. > But a simple linear fit should always work. Or not? Not. It has a higher chance of success, but no guarantee. > Is it true that the Marquardt-Levenberg algorithm is used for all fits? Yes. > Must I provide 'good' starting values for a, b to get a correct result? That, and a sensible model. Models in which parameters would fit zero won't work. ```
 [Gnuplot-info] Re: wrong simple linear fit From: Eckard Specht - 2005-06-17 12:44:50 ```Dear Hans-Bernhard, thank you very much for the explanation. In all interactive gnuplot sessions, such problems can be recognized and avoided. But for 'batch' sessions this strategy is too restrictive. However, gnuplot is a wonderful tool. Here; is the "little helper". Best regards, -Eckard ```