Tadpole
Tadpole

Reputation: 1

Improving fit in gnuplot (by limiting parameter size?)

I'm having trouble fitting the following data in gnuplot 4.4

0.0007629768    -0.1256279199   0.0698209297
0.0007565689    0.5667065856    0.0988522507
0.00071274      1.3109126758    0.7766233743

f1(x) = -a1 * x + b1
a1 = 28000
fit f1(x) "56demo.csv" using 1:2:3 via a1, b1       
plot "56demo.csv" using 1:2:3 with yerrorbars title "56%", \
f1(x) notitle

This converges to values of a1 and b1 which are higher than I would like. Several similar tests converge to values in the range in which they should be, but for some reason these don't.

Specifically, I'd like to have a1 = 28000, approximately.

I'm looking for some way to hit a local minimum. I've tried making the fit limit smaller, but I haven't had much luck that way. Is it possible to set an upper limit to the values of a1 and b1? That is one way I'd like to try.

Thanks

Upvotes: 0

Views: 1687

Answers (1)

sweber
sweber

Reputation: 2996

The most common method of fitting is the chi-square (χ²) method. Chi-square is the expression

enter image description here

where xi, yi and σi are the data points with error in y, and f(x) is a model function which describes your data. This function has some parameters, and the goal is to find those values for the parameters, for which this expression has a global minimum. A program like gnuplot will try several sets of values for this parameters, to find the one set for which χ² is minimal.

In general, several things can go wrong, which usually means that the algorithm has found a local minimum, not the global one. This happens for example when the initial values for the parameters are bad. It helps to estimate the initial values as good as possible.

Another problem is when the algorithm uses too big steps between the sets of parameter values. This often happens for example, if you have a very narrow peak on a broader peak. Usually, you will end up with a parameter set describing a sum of two identical peaks, which describes the broad peak well and ignores the narrow one. Again, a good initial value set will help. You may also first keep the peak positions fixed (i.e. not in the via-list in gnuplot ) and fit all other parameters, and then fit all parameters in a second command.

But if f(x) is a linear function, this problems do not exist !
You can replace f(x) by m*x+b and do the math. The result is that χ² is a parabola in the parameter space, which has a single, unique minimum, which can also be calculated explicitly. So, if gnuplot gives you a set of parameters for that data, this result is absolutely correct, even if you don't like that result.

Upvotes: 0

Related Questions