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:
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.
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?
> 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
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.
<a href=http://hydra.nat.uni-magdeburg.de/praktikum/>Here</a> is the "little