TH1::Chi2TestX with one bin histograms

Hi,

please see the following piece of code using 5.15/08 that creates two histograms with 10 bins of which all are empty except the first one. Running Chi2TestX on this results in chi2=0 and ndf=0:

{
  TH1F h1("h1","",10,1,10);
  TH1F h2("h2","",10,1,10);
  h1.SetBinContent(1,10);
  h2.SetBinContent(1,5);

  Double_t chi2;
  Int_t ndf, igood;
  h1.Chi2TestX(&h2,chi2,ndf,igood);
  cout << "chi2 = " << chi2 << endl
       << "ndf = " << ndf << endl;
}

Isn’t the ndf calculation wrong? Shouldn’t there be 1 degree of freedom?

-Frank

Frank,

I see that ndf is set to nbins-1, then subtracted by 1 for each empty bin.
I have contacted the authors to understand why they set ndf to nbins-1 instead of nbins.

Rene

Hi,

A very down-to-Earth (perhaps too much) explanation can be found at:

cs.wellesley.edu/~cs199/lectures … quare.html

Scroll down to the section “Why is the degrees of freedom like that”.

Cheers,
Anna