dipetkov / eems

Estimating Effective Migration Surfaces
GNU General Public License v2.0
102 stars 28 forks source link

parameterization of negative-bi loglikelihood #20

Open halasadi opened 6 years ago

halasadi commented 6 years ago

Here in the code is the log-likelihood of the NegBi up to a constant (where prob, size) are treated as constants

*
 Log probability mass function of the negative binomial distribution, with
 parameters size (number of failures) and prob (probability of success)
 Also -- log pmf of the zero-truncated negative binomial, with the same parameters,
 as long as k>0, since truncating only changes the constant of proportionality
 Uses gamma(n) = (n-1)!
 */
double dnegbinln(const int k, const int size, const double prob) {
    double pln = -Inf;
    if ( (k>=0) && (size>0) && (prob>0) && (prob<1) ) {
        pln = lgamma(size+k) - lgamma(k+1) + k*log(prob);
    }
    return (pln);
}

However, shouldn't it be

pln = lgamma(size+k) - lgamma(k+1) + k*log(1-prob);

So I think the eems implementation has p as the probability of failure (not the probability of success).

halasadi commented 6 years ago

I am using the Wikipedia article as a reference: https://en.wikipedia.org/wiki/Negative_binomial_distribution