Menu

Question about setting the range for fit function

Help
newkrystal
2023-03-26
2023-10-12
  • newkrystal

    newkrystal - 2023-03-26

    Hello,

    I want to do the linear fitting for my data within a specific range . So, I used
    f(x) = a*x

    fit [800:1400] f(x) "filename" using 1:2 via a. However, it seems to me that the fitting line does not fit well to the range that I specified. Could you help clarify this? I have attached the screenshot below.
    Thank you.

     
  • newkrystal

    newkrystal - 2023-03-26

    screenshot below

     
  • Hans-Bernhard Broeker

    The solution you got is bad because the problem, as stated, is bad.

    There is no better value for 'a' for that (subset of the) data, and that function. The function simply does not fit at all.

     

    Last edit: Hans-Bernhard Broeker 2023-03-26
  • newkrystal

    newkrystal - 2023-03-26

    Thank you. I just have one more question. How can I plot the whole data set and plot the fitted line within a specific region? If I specify the range in the plot function, the range applies for both data set and the fit.

     
  • Tatsuro MATSUOKA

    Perhaps your fit executed in the range where you specifid. y =a x should takes value 0 at x =0 and across the data near the range you specify. If you fit using a * x + b, what happenes?

     
  • newkrystal

    newkrystal - 2023-03-27

    Yes, the equation should be y=ax+b. we could not just set the intercept to be zero, which is not possible to fit the linear region in the data set. Also, when I make the plot, how can I plot the whole data set and the fit which is only from [800:*].?
    The range in the plot function applies to both the data and the fit. I could not specify the range for each of them.
    Thank you.

     
  • Tatsuro MATSUOKA

    $dat << EOD
    0, 0
    1, 1.1
    2, 3.9
    3, 8.8
    4, 18.2
    5, 24.7
    6, 36.0
    7, 48.5
    8, 64.3
    9, 80.9
    10, 100.2
    EOD
    
    fit [6:11] a * x + b $dat using 1:2 via a, b
    plot $dat, a * x + b
    
    After 1 iterations the fit converged.
    final sum of squares of residuals : 15.124
    rel. change during last iteration : -7.51698e-15
    
    degrees of freedom    (FIT_NDF)                        : 3
    rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 2.24529
    variance of residuals (reduced chisquare) = WSSR/ndf   : 5.04133
    
    Final set of parameters            Asymptotic Standard Error
    =======================            ==========================
    a               = 16.08            +/- 0.71         (4.416%)
    b               = -62.66           +/- 5.768        (9.206%)
    
    correlation matrix of the fit parameters:
                    a      b      
    a               1.000 
    b              -0.985  1.000 
    
     

    Last edit: Tatsuro MATSUOKA 2023-03-27
    • Karl Ratzsch

      Karl Ratzsch - 2023-03-27

      You can (should, usually, from a scientific point) also limit the plot to the range for which you did the fit.

      plot sample [6:10] a * x+b lc 1 lw 3 title "fit region", \
         [3:6] a * x + b lc 1 title "extrapolation", \
         $dat
      
       
  • newkrystal

    newkrystal - 2023-03-27

    Thank you. As I want to show the the transition from non-linear to linear region, I want to plot the whole data. However, for the fit, I only want the fit to cover the specified range on the plot (like what we do in excel). I was wondering how we can do that.

     
  • Tatsuro MATSUOKA

    I executed Karl's suggestion after my script and got the attached the plot. As far as my understading, this is what you want, is not it? (I want to plot the whole data. However, for the fit, I only want the fit to cover the specified range on the plot )

     

    Last edit: Tatsuro MATSUOKA 2023-03-28
  • Earl Mitchell

    Earl Mitchell - 2023-10-12

    Appreciate your input. I'm working on plotting a dataset and would like to illustrate the transition from non-linearity to linearity. While I intend to show the entire dataset, I'm interested in limiting the fit to a specified range, akin to Excel's functionality. Is there a method to accomplish this tailored range for the plot?

     
    • Reginald Beardsley

      Specify the range of the fit as the first argument c.f. 'he;p fit'

       On Thursday, October 12, 2023 at 01:41:50 PM CDT, Earl Mitchell <earl788@users.sourceforge.net> wrote:
      

      Appreciate your input. I'm working on plotting a dataset and would like to illustrate the transition from non-linearity to linearity. While I intend to show the entire dataset, I'm interested in limiting the fit to a specified range, akin to Excel's functionality. Is there a method to accomplish this tailored range for the plot?


      Question about setting the range for fit function


      Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/gnuplot/discussion/5925/

      To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.