Wrong error estimates

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:

void gerade()
{
Double_t x[3]={1,2,3};
Double_t y[3]={0.95,2.05,2.98};

TCanvas *gerade=new TCanvas(“gr”,“Line”);
TGraph gr=new TGraph(3,x,y);
gr->Draw("a
");

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

errorp *= sqrt(chisquare/ndf)
Rene

First of all, thanks for your reply.

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++).

post the exact script reproducing the problem. You do not need to apply the correction. It is automatically applied by the Fit function when ndf>1

Rene

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.

I also have another problem:

void test(){ TCanvas *c=new TCanvas("c","hallo"); Double_t a=200; TF1 *gausskurve=new TF1("gausskurve","a*exp(-0.5*(x-7.5)^2/0.1)",6,10); gausskurve->Draw(); }

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?

Thanks for your help!!!

[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.

[quote]I also have another problem:

void test(){
TCanvas c=new TCanvas(“c”,“hallo”);
Double_t a=200;
TF1 gausskurve=new TF1(“gausskurve”,"aexp(-0.5
(x-7.5)^2/0.1)",6,10);
gausskurve->Draw();
} [/quote]

Do

void test(){ TCanvas *c=new TCanvas("c","hallo"); Double_t a=200; TF1 *gausskurve=new TF1("gausskurve",Form("%g*exp(-0.5*(x-7.5)^2/0.1)",a),6,10); gausskurve->Draw();

or

void test(){ TCanvas *c=new TCanvas("c","hallo"); Double_t a=200; TF1 *gausskurve=new TF1("gausskurve","[0]*exp(-0.5*(x-7.5)^2/0.1)",6,10); gausskurve->SetParameter(0,a); gausskurve->Draw();

Rene

Thanks a lot.

I used the second method and it works perfectly…

Cheers

Christian