# NB distribution

Hello!
i try to fit my data with Negative Benomial Distribution. so, first of all i can’t to write this function in routine. Problem is in tgamma function. in block of code like that

Double_t myFunc_1jet(Double_t *x, Double_t *par) {
Double_t f= ROOT::Math::tgamma(xx) * par;
return f;
}

i catch the exception "tgamma is not defined in current scope ". so, two question :

1. is already NB in code of ROOT or somewhere else
2. what’s the problem in code.
Thank you for response!

Hi,

the negative binomial is not defined yet in ROOT> We could add for one of the next release. However is easy to implement in term of the gamma (or better log of the gamma) function.
Here is an example of code implementing the probability density function:

``````#include <cmath>
#include "Math/SpecFunc.h"

double negative_binomial_pdf(int k, double p, double r) {
double a = ROOT::Math::lgamma(k+r) - ROOT::Math::lgamma(k + 1) - ROOT::Math::lgamma(r);
return std::exp(a) * std::pow(p, r) * std::pow(1-p, (double) k);
}``````

``#include "Math/SpecFunc.h"``