Not able to fit data points

I’m trying to fit data points by three functions, namely fun1, fun2, and fun3, to check which one is fitting the best. But I’m unable to do that: for fun1 chi^2/ndf is not near 1, for fun2 the parameters 2 and 3 is showing large errors, for fun3 not able to fit at all!

As per my understanding of the data points, fun3 should fit good but it’s not coming. Please find attached the macro.

Thank you in advance.
null_fit.cpp (1.8 KB)

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Draw your function with your initial values of parameters and see if it behaves like your data.

Thank you for replying @Wile_E_Coyote . I’ve plotted the functions with initial values that I’m using to fit the data points, please see the attached image. I’ve updated the macro also to accommodate this. But still the same bad fitting is happening. Could you please check?


Try to add “EX0” to your fit options.

BTW. Instead of “(x/[1])**-[2]”, use “pow(x/[1],-[2])”.

@Wile_E_Coyote the macro file above is the updated one. I’ll check this option.

Do not use the “W” option (your data points are spread over many orders of magnitude in “y”, so their “y” errors always need to be correctly taken into account).

I’m using “EX0RQN” in the initial pre-fit and the option “R” in the final fit. But the same outcome. And, I don’t know why fun3 is not fitting at all!

BTW. The “R” option doesn’t matter (you anyhow fit all data points).

I did this change that you’ve suggested. I’m getting the attached fitting for the three functions. You can see that in fun2, error in p2 is large. Similarly, error in p1 is large in fun3.
So, how to decide which one to use finally? Also, is chi2/ndf reliable here, in all the three cases?
Below is fun3:

Below is fun2:

Below is fun1:

It seems to me that in “fun3”, the parameters “0” and “3” are correlated with the parameter “1”.


TF1 *f = new TF1("fun3", "[0]*pow(x/[1],-[2])-[3]*log10(x/[1])", xmin, xmax);
f->SetParameters(2.e-10, 1., 2., 0.); f->FixParameter(1, 1.); // for fun3

This is what I’m getting now for fun3 (see attached).
So, may you suggest which function I finally choose? Also, should I take chi2/ndf seriously in all the three cases? If so, then for fun1 it’s 0.14 and for fun3 it is 0.11, so should I go with fun3?

The analytical formula of the fit function should be decided by the “physics” that it is supposed to describe, not by the “chi2”.

Just for fun:

TF1 *f = new TF1("fun4", "[0]*pow(x,-[2])-[3]*log10(x)+[1]", xmin, xmax);
f->SetParameters(2.e-10, 0., 2., 0.); // for fun4
gr->Fit(f, "EX0"); // initial pre-fit
gr->Fit(f, ""); // final fit

Thanks @Wile_E_Coyote

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.