# Problem With Negative Binomial Distribution and Double_t

Hello all,

I am trying to fit some experimental data which is described by a negative binomial (Polya) distribution. The problem is that the Polya distribution looks like:

Polya(x,par)= par(TMath::Gamma(x+par)/(TMath::Gamma(x+1)TMath::Gamma(par)))(TMath::Power((par/par),x))(TMath::Power((1+(par/par)),-x-par));

with parameters such as:
SPE->SetParameter(0,1.0);
SPE->SetParameter(1,10);
SPE->SetParameter(2,40);

The problem arises because my histograms are (0,1000) in x and so the TMath::Power(a,x) overflows the
limits of a Double_t variable. So I “inf/nan” propagated to pad errors. Since I am using this distribution with the root fitting routines and the build-in Root TMath functions it is not so simple to change all of the variables to long double.

I am beating my head against this problem to find a solution, but I haven’t come up with anything yet. Any ideas wold be great.

Thanks!

1 Like

Hi,

You can use the ROOT definition of the negative binomial ,

and create then from it a TF1 for fitting

TF1 * f1 = new TF1(“f”,"*ROOT::Math::negative_binomial_pdf(x,,)")

Lorenzo

1 Like

Okay, Great!

The ROOT::Math::negative_binomial_pdf() function works perfectly. I unfortunately didn’t see it, because I only look in the TMath function list.

Thanks!

I am trying to fit a distribution with negative binomial distribution ( NBD) . It works with small values of ‘n’ but for large values of ‘n’ it throws out. I tried using the fit function below but it returns me same values of parameters as given by SetParameter

TF1 * tf2 = new TF1(“tf2”,"*ROOT::Math::negative_binomial_pdf(x,,)");
tf2->SetParameter(0,2000);// normalization constant
tf2->SetParameter(1,130); // k parameter
tf2->SetParameter(2,55); // mean multiplicity

TF1 *fit1 = new TF1(“fit1”,"TMath::Gamma(x+)/(TMath::Gamma(x+1)TMath:: Gamma())(TMath::Powe
r((/(+)),x))
(TMath::Power((/(+)) ,))");
fit1->SetParameter(0,1e5);// normalization constant
fit1->SetParameter(1,130); // k parameter
fit1->SetParameter(2,60); // mean multiplicity

This did not work. It works for small value of ‘n’.

Any suggestion will be great help.

Thanks
Brijesh

1 Like

Hi,

I think you are using the function with the wrong parameters. The definition for

ROOT::Math::negative_binomial_pdf( k, p, n)

is similar to the one at

mathworld.wolfram.com/NegativeBi … ution.html

where x is k and r-1 is n

So maybe in your case you want to have

TF1 * tf2 = new TF1(“tf2”,"*ROOT::Math::negative_binomial_pdf(,x,)");

?

Best Regards

Lorenzo

1 Like

question What is the k?

Hi,
Please open a new thread instead of bumping one that’s 6 years old! See the docs for an explanation of the notation.

Cheers,
Enrico

Bumping one that’s 6 years old?

Interesting choice of words. Almost have a bit of arrogance. If it’s 6 years old and you don’t reply to forums that’s old , why is it still up? And why did you respond so quickly?

The inquiry was from Scientist from a National lab pertaining to a polya equation .once it was entered it directed us to the question. Honestly i don’t think you saw the question. I could be wrong. My question was simply what was the k in the equation.

If you have become bored , overwhelmed, or filled with who because you have mastered root , why not let someone humble answers emails and questions.

Your comment is being used to show students “when arrogance go wrong”

Enrico is it?

Today ain’t good for you

Now ,

Bumping one that’s 6 years old? Ummm
Interesting choice of words. It almost have a bit of arrogance hidden in the words.Question, If it’s 6 years old and you don’t reply to forums that’s old , why is it still up? And why did you respond so quickly?

The inquiry was from Scientist/Physicist , from a National lab pertaining to a polya equation for fitting .We entered the keywords and it directed us to the question to this site. Honestly i don’t think you saw the question. I could be wrong. My question was simply what was the( k )in the equation.

If you have become bored , overwhelmed, or filled with ego because you have mastered root , why not let someone humble answers emails and questions.

Your comment is being used to show students “when arrogance go wrong”

About your question: my answer was admittedly terse, but the link I provided to the `negative_binomial_pdf` function documentation should clarify what `k` represents in the equation. Sometimes links within forum posts do not display correctly in email clients – in case that’s the source of the misunderstanding, here is the full link: https://root.cern.ch/doc/master/group__PdfFunc.html#ga4a9cab35372227aa21c2de11f625325e. To save you a click, if I understand correctly `k` represents the number of failures.