c# - Math.Net Numerics: Error in sampling from Negative Binomial -
i'm using math.net sample values overdispersed poisson distribution. i'm doing using negative binomial link, described here: https://stat.ethz.ch/pipermail/r-help/2002-june/022425.html
my code looks this:
private static double odpoisson(double lambda, double dispersion) { double p = 1 / (dispersion - 1); double r = lambda * p; if (dispersion == 1) { return poisson.sample(lambda); } else { return negativebinomial.sample(r, p); } }
what i've found works low values of lambda. try sample lambda of 1000 , dispersion parameter of 2, code 'hangs', i.e. method keeps running no value returned. i've looped through method test various combinations of input parameters (lambda 1 1000, dispersion = 2), , code 'hangs' @ different combinations every time. it'll sample combinations lambda = 750, other times lambda = 500. happens re-running console app , making no code changes.
i've included 'isvalidparameterset' check before every run, , though parameters considered valid, sample still not generated. further test whether input parameters valid, i've tested same parameters negativebinomial.cdf method @ 50th percentile, , returns value every time.
is there error in negativebinomial.sample method? if not, how fix problem?
Comments
Post a Comment