Mean uncertainity of a fit function

Hi everyone,

I am fitting a TGraphErrors() using a TF1() function.

auto g = new TGraphErrors(n,x,y,nullptr, err_y);
TFitResultPtr r = g->Fit(func, "WRS");

I am wondering how to obtain the mean uncertainty in the fitted function. I am unsure what the exact term for this in statistics is. It represents the average of two sigma bounds for each f(x). f = fit function, and x is the x-axis value.
To clarify a bit more the two red dashed lines around the fit
image

Is there any pre-defined functionality in ROOT for this?

Please share for any additional information from my side.
Thanks a lot.

Dear @utkarsh-2000 ,

Thanks for posting on the forum! Yes ROOT provides facilities to get the confidence interval of your fit. From the TFitResultPtr object you can call r->GetConfidenceIntervals(). See this tutorial for an example usage with plots.

Cheers,
Vincenzo

2 Likes

Hi @vpadulan,
Thanks for your answer.
Correct me if am wrong, the GetConfidenceIntervals() only returns the confidence intervals at the points used for fitting, right ?

I was trying the other signature

double ci[2];
        double points = {345.};
        int stride1 =1, stride2 = 1;
      GetConfidenceIntervals(1, stride1, stride2, points, c1, 0.683, true) ; 
        std::cout << "The confidence level is " << ci[0] << std::endl;

However, I am getting.

error: no matching member function for call to 'GetConfidenceIntervals'
      r->GetConfidenceIntervals(1, stride1, stride2, points, c1, 0.683, true) ; 

Can you please help on how to get confidence intervals of unknown points n fitting range?
Thanks a lot

Dear @utkarsh-2000 ,

You are not calling any existing signature like this. I guess what you are trying to do is calling this signature ROOT: ROOT::Fit::FitResult Class Reference where x and ci are arrays but in your case they are not arrays so you should correct that.

Can you please help on how to get confidence intervals of unknown points n fitting range?

About this I am not sure, probably @moneta or @couet know. But in general, the tutorial shows you how to draw the line for the confidence intervals over the entire fit, if you only need to draw and not get the actual values.

Cheers,
Vincenzo

1 Like

I guess @moneta might know better.

Hi,

Yes, the function you need for this is FitResult::GetConfidenceIntervals. You can compute the fitted function uncertainty (band) at the fitted points or on whatever points you provide. Afterwards you can create a TGraph from these points and using interpolation display as in the above figure. You can choose teh desired confidence value (e.g 95% as above) and also to re-normalize the uncertainty using the obtained fit chi-square. This is needed when you don’t have uncertainty on data points as above.

Lorenzo

1 Like

Thanks a lot @vpadulan for the help.

Thanks @moneta for the detailed explanation on obtaining the confidence bands

Just to clarify when fitting without the “W” we need this re-normalization and it can be done by the true flag in GetCoincidenceIntervals(), right?

Hi,

The normalization is automatically done when using option “W”, so it is not needed in this case. When fitting a TGraphErrors, and the errors are correctly estimated you might want not to apply this re-normalization.

Lorenzo

1 Like

Thanks a lot @moneta for the clarification.