Fit/Plot disparity

Help
Anonymous
2011-11-20
2013-02-10

  • Anonymous
    2011-11-20

    As I understand, it is intended that plot 'data' and fit f(x) 'data' handle the using directive the same way. That is the case with simple statements such as

    plot 'data' using 1:5
    

    I ran into problems with the following

    plot 'data.txt' using 1:5:2:6 with xyerrorbars
    f(x)=2*d*x
    fit f(x) 'data' using 1:5:2:6 via d
    

    The plot looks ok, but the fit is way off. If i use just the y delta, as in using 1:5:6, i get an approximately right result but i would be discarding some of the data that i have. Also, the fitting just the data points (using 1:5) produces wrong results. My data is here, just for reference and your experiments:

    0.0615822448    0.0012887153    0.1134595072    0.0013933442    2.7423717678446E-011    3.43072445555148E-014
    0.0570362578    0.0012829691    0.0988864172    0.0013559311    2.45285187699072E-011   2.45593666877898E-014
    0.0507041034    0.0012757683    0.089373837 0.001335138 2.23913717207784E-011   1.86932593022197E-014
    0.0471009753    0.0012720785    0.082797564 0.0013223007    2.07303820005753E-011   1.48438934839168E-014
    0.0444052455    0.0012695077    0.0781375184    0.0013139256    1.93914967357746E-011   1.2158667178527E-014
    0.0408190891    0.0012663361    0.074430107 0.0013076751    1.82824784522973E-011   1.01982612392671E-014
    0.0390292728    0.0012648582    0.0689007851    0.0012990114    1.73442819546629E-011   8.71568463521521E-015
    

    How do i fix it?

     

  • Anonymous
    2011-11-20

    Whoops, the file is called data.txt and I obviously did the fit with that, not just 'data' which would not have worked. That is not the issue here.

     
  • Your problem is that while plot and fit do indeed treat 'using' etc. identically, that does not mean they must do the thing with the data once read.  fit simply has no equivalent to plot's xyerrorbarrs style, so it cannot treat the data the same way your plot command does.  Four using specifiers in a 'fit' command turn it into a 3D fit.  Please consult more of "help fit" to understand what your commands actually do.

     

  • Anonymous
    2011-11-20

    Hmm, the original post was likely a bit misleading. I have read the documentation and done several hours worth of googling, but i didn't find a way to make a fit that takes into account uncertainties in both directions. The only logical extension to that three column form (using 1:5:6) was what i tried, but that didn't work.

     
  • Well, like I said, the thing you were looking for could not be found because it doesn't exist.  There really is no sane way for a non-linear, generic least-squares fitting algorithm to take into account uncertainties in the x direction -- the algorithm itself doesn't even recognize the eixstence of x values, as such.  For all 'fit' really wants to know, the input consists of a sequence of triplets:

       * value
       * error
       * function of several parameters

    Fits where these many separate functions are actually the same function with an additional argument 'x', evaluated at different 'x' values, are a special case of that.  Errors in those 'x' values don't enter the picture in any way, nor can they be forced into it in any reasonable way.

     

  • Anonymous
    2011-11-20

    nor can they be forced into it in any reasonable way.

    One can always invert the function an fit that.
    In this case it is still a linear problem and I can do a fit using 5:1:2 and deduce the parameter d from that. That way i get to use the larger error estimates from x.

     
  • One can always invert the function an fit that.

    No, one can't always do that.  Linear fits are a very special case.  'fit' is for the general case.

     

  • Anonymous
    2011-11-20

    Every continuous function on the real line has partial inverses, one between every two local extrema. So, in principle, it is possible, though it will become a bit more complicated when there are only partial inverses. This time there are no local extrema, so there is a true inverse for the whole function. Linearity has nothing to do with it. For a non-linear example, consider exp(x) and log(x).

     

  • Anonymous
    2011-11-22

    Besides, i see no reason why one cannot put 2d normal distributions around those (y,x) pairs and try to find the curve with maximum likelihood. I admit that I'm not a real statistician, but to me it seems simple enough.

     
  • Ethan Merritt
    Ethan Merritt
    2011-11-23

    You are quite correct that one can use maximum likelihood to account for errors on both x and y.  Unfortunately, that isn't implemented in gnuplot.