Search code examples
gnuplotgnuplot-iostream

Is there any error variable for gnuplot fit?


I'm making a c++ code which prints commands for gnuplot, in order to plot different things faster. The code plots the data already as the data fit as well, but now I'm adding some labels, and I want to print the fit equation, I mean something with this form

f(x) = (a +/- Δa)*x + (b +/- Δb)

I have the following line for printing it

set label 1 at screen 0.22, screen 0.75 sprintf('f(x) = %3.4f*x + %3.4f', a, b)

But, as you can see, there is only a and b values with no errors, I was thinking something like put there in the sprintf function any error related variables (FIT_something) and then have something like

set label 1 at screen 0.22, screen 0.75 sprintf('f(x) = (%3.4f +/- %3.4f)*x + (%3.4f + %3.4f)', a, deltaa, b, deltab)

But I can't find those, my answers are: does those exists? and if the answer is no, is there any way to print the variable errors further just writing it explicitly on the line?

Thanks for your help


Solution

  • Please read the statistical overview section of the gnuplot documentation (help statistical_overview). Keeping in mind the caveats described there, see also the documentation for set fit errorvariables, which I extract below:

     If the `errorvariables` option is turned on, the error of each fitted
     parameter computed by `fit` will be copied to a user-defined variable
     whose name is formed by appending "_err" to the name of the parameter
     itself.  This is useful mainly to put the parameter and its error onto
     a plot of the data and the fitted function, for reference, as in:
    
            set fit errorvariables
            fit f(x) 'datafile' using 1:2 via a, b
            print "error of a is:", a_err
            set label 1 sprintf("a=%6.2f +/- %6.2f", a, a_err)
            plot 'datafile' using 1:2, f(x)
    
     If the `errorscaling` option is specified, which is the default, the
     calculated parameter errors are scaled with the reduced chi square.  This is
     equivalent to providing data errors equal to the calculated standard
     deviation of the fit (FIT_STDFIT) resulting in a reduced chi square of one.