I want to do a linear fit. I get the right values and chi2 but the error estimates are wrong (they even stay the same when I change data points). I also used the fit panel an took a polynomial of degree one which didn’t change the result.
Here’s the code I used:
TF1 *f1 = new TF1(“f2”,"[0]+[1]*x");
gr->Fit(f1);
}
The parameter estimates are correctly estimated (checked with excel):
p0=-0.0367
p1=1.015
chi2=0.0048
But the errors are completely wrong:
error p0=1.528
error p1=0.707
I’m using root 5.14 with windows XP.
Thanks a lot for your help.
When fitting a TGraph (ie no errors associated to each point), a correction is applied to the errors on the parameters with the following formula when ndf>1
errorp *= sqrt(chisquare/(ndf-1))
In your case with 3 points, ndf=1, so the important correction on the parameter errors cannot be made. Simply add a 4th point to see the right error.
However, I believe (to be checked) that a better correction could be in case ndf=1
Unfortunately it didn’t work. Now I did a linear fit with 9 data points,
all of them along a straight line (only one a little bit off). The parameter errors still remain very large.
To other suggestion to copy the line errorp *=…
in my script also didn’t work, there was an error message afterwards
(I just copied the line and pasted it in my script. Is that what I’m supposed
to do? I really am a beginner with root / c++).
I don’t know what I did wrong yesterday but somehow it works now. But the error estimates are only correct if I use
function->GetParError(0)
and they are also displayed correct in the histogram but they are wrong in the terminal. I don’t know why this is.
doesn’t work. But if I insert the number 200 directly in the function then works. But I want to use parameters that are calculated earlier in the program. How do I do that?
[quote]I don’t know what I did wrong yesterday but somehow it works now. But the error estimates are only correct if I use
function->GetParError(0)
and they are also displayed correct in the histogram but they are wrong in the terminal. I don’t know why this is. [/quote]
This correction is applied by TGraph::Fit after calling Minuit.
The output on stdout is from Minuit.