ROOT::Math::chisquared_cdf

Hello, I read a question from someone who was getting a chi2 value for a fit function that was too high comparing to how well the fit function described the set of points. I am getting the same problem and I read somewhere I should use chisquared_cdf. However, its arguments are x (the point to where I want the integral to be calculated) and r (number of fit points). What value do I introduce in x and how to I express that I want to know the value for chisquared_cdf of my specific fit function, since there’s no TF1 argument ?

Is there otherwise another way to get a lower value of chi2 for my fit function?

Hi,
the function chisquared_cdf compute the integral of the chisquare probability density function from 0 to x. What you would like to obtain is instead 1. - this, i.e. the function chisquared_cdf_c, which compute the integral between x and +infinity.
See ROOT: Cumulative Distribution Functions (CDF).
In case of a fit, you obtained after the fit a chi2 value, from ROOT::Math::FitResult::Chi2() and the number of degree of freedom (= number of points - number of fit parameters), from ROOT::Math::FitResult::Ndf() .
This you can pass to chisquared_cdf_c to obtained the p-value of the fit, i.e. the probability of having
chisquared value larger than what you observed, i.e. P(Chi2 > chi2_your_fit). If this probability is very small, it means that the hypothesis that your fit function is agood representation of your data is very unlikely. See any book on statistics about this.
An example:

{
auto h1 = new TH1D("h1","h1",50,-3,3); 
h1->FillRandom("gaus"); 
auto result = h1->Fit("gaus","S"); 
double chi2 = result->Chi2(); 
double ndf = result->Ndf(); 
double pvalue = ROOT::Math::chisquared_cdf_c(chi2, ndf); 
std::cout << "p value of the fit  : " << pvalue << std::endl;
}

Lorenzo

so, it shall return a value between 0 and 1?

Yes, the p-value is in [0,1] and uniform distributed in case the null hypothesis is correct.

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