# 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[0](TMath::Gamma(x[0]+par[1])/(TMath::Gamma(x[0]+1)TMath::Gamma(par[1])))(TMath::Power((par[2]/par[1]),x[0]))(TMath::Power((1+(par[2]/par[1])),-x[0]-par[1]));

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â,"[0]*ROOT::Math::negative_binomial_pdf(x,[1],[2])")

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â,"[0]*ROOT::Math::negative_binomial_pdf(x,[1],[2])");
tf2->SetParameter(0,2000);// normalization constant
tf2->SetParameter(1,130); // k parameter
tf2->SetParameter(2,55); // mean multiplicity

Earlier I had used
TF1 *fit1 = new TF1(âfit1â,"[0]TMath::Gamma(x+[1])/(TMath::Gamma(x+1)TMath:: Gamma([1]))(TMath::Powe
r(([2]/([2]+[1])),x))
(TMath::Power(([1]/([2]+[1])) ,[1]))");
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â,"[0]*ROOT::Math::negative_binomial_pdf([1],x,[2])");

?

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â

Excuse all typos. Go read the question idiot and answer it.

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â

Excuse all typos. Go read the question idiot and answer it.

Hi Anthony,
Iâm sorry my quick reply came off as arrogant, it was not my intention.

The thread is still up because we never delete any content that might turn useful. Necro-bumping (not my choice of words) threads is typically discouraged in forums for the reasons explained e.g. at this link.

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.

Cheers,
Enrico

4 Likes