# Fit uncertainties

Hello,

Is there a way to get the uncertainty of a fit at a given point?

Thanks,
Raz

Hi,
you can use FitResult::GetConfidenceIntervals. Here is an example (supposing h1 is your histogram you want to fit):

``````TFitResultPtr r = h1->Fit("gaus","S");
double xpoint[1] = {1} ; // give location of point
double error[1];
double cl = 0.683;   // desired confidence level
r->GetConfidenceIntervals(1,1,0,xpoint,error,cl);``````

Lorenzo

Thank you Lorenzo, I wasn’t aware of TFitResult

I attached a small script in which I fill a histogram and fit it with a 1st order plynomial.

I then try what you suggested, as well as my own calculation based on the covariance matrix (I hope I’m doing this right…)

I’m getting totally different numbers, so either I’m doing it wrong or I don’t understand what the GetConfidenceIntervals method returns.

Can you please take a peak at that?

Thanks,
Raz
cl.C (680 Bytes)

Hi,

the functions return the interval normalized by the observed chi2 value. If you want the un-corrected interval you should then apply this correction factor:

`````` double level = 0.68269;  /// 1 -sigma intervals
r->GetConfidenceIntervals(1, 1, 0, point, interval, level);

double rawInterval = interval[0]/( sqrt( r->Chi2() / r->Ndf() ) * TMath::StudentQuantile(0.5 + level/2, r->Ndf()) ) *  ROOT::Math::chisquared_quantile(level,1) ``````

In this case you get the same result as your calculation. I should probably add an option to the routine to return this un-corrected interval.

Best Regards

Lorenzo

That’s great, Lorenzo. It does reproduce my calculation.

Thanks a lot,
Raz

Hi,

I have added an option in FitResult::GetConfidenceIntervals to not normalize the interval with the chi2 value
Just call (using the ROOT trunk after revision 37438):

``r->GetConfidenceIntervals(1, 1, 0, point, interval, level,false);``

Lorenzo