Fitting w/ negative binomial distribution

Hi,

I am trying to fit some data with a negative binomial distribution (NBD). This works for distributions with low values of the k parameter (k<40), but as k increases the fit breaks down with the message,

<<
Warning in TH1F::Fit: Abnormal termination of minimization.
FCN=nan FROM MIGRAD STATUS=CALL LIMIT 5010 CALLS 5011 TOTAL
EDM=nan STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 nan 1.89397e+05 nan nan
2 p1 nan 1.13240e+01 nan nan
3 p2 nan 4.50000e+01 nan nan

If I go to the limit and use a Poisson fit, it works out fine. Are there any suggestions to get this fit to work properly over a larger range?

Thanks.

Here is the fit I’m defining:

TF1 fit1 = new TF1(“fit1”,"[0](TMath::Gamma(x+[1])/(TMath::Gamma(x+1)TMath::Gamma([1])))(TMath::Power(([2]/[1]),x))*(TMath::Power((1+([2]/[1])),-x-[1]))");

fit1->SetParameter(0,1.);// normalization constant
fit1->SetParameter(1,100); // k parameter
fit1->SetParameter(2,500.); // mean multiplicity

1 Like

Could you post the shortest possible running script reproducing your problem?

Rene

Hi Rene,

I am trying to generate a data file small enough to upload, but I need an AFS link that is currently down.

I will post everything in the next message.

Thanks,

Terry

Hi again,

I have attached a sample of some data that I have been trying to fit, along with a small macro that reproduces what I have been seeing.

Thanks,

Terry
nbd.C (855 Bytes)
nbd_test.root (655 KB)

1 Like

[quote=“tjt”]Hi again,

I have attached a sample of some data that I have been trying to fit, along with a small macro that reproduces what I have been seeing.

Thanks,

Terry[/quote]

Let me add, in the macro the first part demonstrates that the fit works for the low multiplicity distributions (lower k values), but in the second part breaks down at higher values.

Cheers,

Terry

Hi,

I see in your function expression things like

TMath::Power(([2]/[1]),x)

I see in your initial setting fit2->SetParameter(2,323.) and
and x runs from 0 to 80 !!

Ever given thought to the numerical range of a double

The warning " Warning in TCanvas::ResizePad: Inf/NaN propagated to the pad. Check drawn objects." is another hint .

Eddy

Hi,

You’ll have to clue me into this problem. The first histogram drawn is from x = 0-80, but that corresponds to fit1,

fit1->SetParameter(2,38.);

That one fills and is fit nicely.

fit2 goes with histogram h2 on the next canvas. The range for this (if you plot it on its own) is 120-490, and

fit2->SetParameter(2,323.);

is within the range.

Thanks,

Terry

Terry,

You request in the fit to calculate numbers like 38^80 which is
fine but in the next fit 323^490 and this can not be represented
by a double .

Eddy

Hi,

Sorry, I was away for awhile.

Thanks. I overlooked the fact that the quantities were defined as doubles. Do I have to define the entire fit function in terms of long doubles?

Thanks,

Terry