# Roofit: Goodness-of-fit (chi2?) in unbinned likelihood

Hello,

Would anyone have a code snippet of how to return some goodness-of-fit value for an unbinned likelihood fit? In particular, how would I print a chisquared value on a unbinned liklihood fit? I assume I need to generate a binned histogram to get this chisquared? I also see there is a rooabsgoodnessoffit class, but the documentation is sparse on this one too.

james

1 Like

Hi,

I don’t have a Root-specific comment, but 1) the likelihood itself is something of a goodness of fit (although hard to interpret) and 2) I think you’re on the right track by making a binned histogram. If you are using the standard Gaussian chi^2, you may want to rebin so that you have at least 10 expected entries per bin (20 works even better). There are other chi^2 that work on small expected numbers of events.

``````Good luck,
Charles``````

I don’t think this is correct. The subject has been discussed in past phystat meetings, see for example the following paper of phystat 2003:

slac.stanford.edu/econf/C030 … OCT001.pdf

and if you want to know more on the subject you can look also at the CDF statistics page:

www-cdf.fnal.gov/physics/statist … .html#fit4

The suggestion of binning the data carefully using the chi^2 test is correct.

Lorenzo

Hi,

I agree with Lorenzos observations on goodness-of-fit in general.

Just to add a RooFit-specific comment. If you have a one-dimensional fit,
it is easy to get a chiSquare/nDOF if you make a plot of your fit

RooPlot* frame = x.frame(Bins(40)) ;
data->plotOn(frame) ;
pdf->plotOn(frame) ;
Double_t chi2 = frame->chiSquare(nFloatParam) ;

For >1D fits this clearly works too but doesn’t tell the whole story in that case. One could make a multi-dimensional chi^2, e.g. as follows

RooChi2Var chi2(“chi2”,“chi2”,pdf,data) ;
Double_t val = chi2.getVal() ;

which would be the ‘raw’ chi2, i.e. not per d.o.f, but be aware that this is tricky because you tend to have many empty and low statistics bins for >1D datasets. Multi-dimensional goodness-of-fit is generally a hard problem.

Wouter

So is there a way to return the number of floating or the number of fit parameters from a rooabspdf/rooplot?

Right now I have to manually put in the number of degrees of freedom into chisquare() funciton. I tried scouring the class libraries, but I can’t seem to find this.

thanks again.
james

Hi,

From a RooAbsPdf you can get the set of floating parameters as follows

RooArgSet obs(…) ; // Set with your observables
RooArgSet* flparams = pdf->getParameters(obs)->selectByAttrib(“Constant”,kFALSE) ;

The number you want is then flparams->getSize() ;

Wouter

1 Like