# Chi2 distributions

Hello ROOTers,

I want to draw several chi2 distributions. I presume they already have been defined somewhere inside Root. However, I was not able to find them yet. Can anybody help me?

Thanks,
Oliver

Not sure to understand what you are requesting.
see TMath functions.

Rene

Oliver is asking for the following recipe :

#include “Riostream.h”
#include “TCanvas.h”
#include “TF1.h”
#include “TH1.h”
#include “TLegend.h”

Double_t ChiSquareDistr(Double_t *x,Double_t *par)
{
// Chisquare density distribution for nrFree degrees of freedom

Double_t nrFree = par[0];
Double_t chi2 = x[0];

if (chi2 > 0) {
Double_t lambda = nrFree/2.;
Double_t norm = TMath::Gamma(lambda)*TMath::Power(2.,lambda);
return TMath::Power(chi2,lambda-1)TMath::Exp(-0.5chi2)/norm;
} else
return 0.0;
}

void doit(Int_t nrFree)
{
TF1 *f1 = new TF1(“chi-square distribution”,ChiSquareDistr,0.01,10,1);
f1->SetParameter(0,Double_t(nrFree));
f1->SetLineColor(49);
f1->Draw(“AC”);

f1->GetHistogram()->SetXTitle(“chi2”);
f1->GetHistogram()->SetYTitle(“density”);
f1->GetHistogram()->SetMinimum(0.0);
f1->GetHistogram()->SetMaximum(1.0);
}

Although all the necessary building blocks (in particular the Gamma
function) are available, it would ne nice if we would make a class
TStat in which all the important densities are calculated . A format
like above would be nice so that they can be used as TF1’s . Then
the distribution can be calculated through the integration function
of the TF1 .

Eddy

Oliver, Eddy,

If what you are looking for is the computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom , this function is already defined in TMath::Prob.
You can get a simple graphics interface with, eg
TF1 f1(“f1”,“TMath::Prob(x,[0])”,.01,10)
f1.SetParameter(0,2)
f1.Draw()

Rene

Great! That’s exactly what I’ve been looking for.
Thanks a lot,
Oliver

To make this a bit more complete, we should add the
Student’s t-distrubution and the F-distribution .

The Name TMath::Prob could use improvement !