fit_nbinom icon indicating copy to clipboard operation
fit_nbinom copied to clipboard

log likelihood wrong?

Open PDiracDelta opened this issue 5 years ago • 2 comments

EDIT: I just checked the results for my data set and compared to R output. Indeed, your version seems to give the correct answers. Why, though (read my post below)?

in log_likelihood I think you switched the terms with p and 1-p. If you check on wikipedia, the p is in the term with ln that is summed over, and the 1-p is in the term with ln that is not summed over. In your code, it's the other way around. You can verify using the R ?dnbinom that its definition of p is identical to that of wikipedia (you are using R's suggestion for estimating p (or prob).

Also, you are returning -result instead of result, which I also think is incorrect.

PDiracDelta avatar Oct 02 '19 08:10 PDiracDelta

Maybe these 2 things are related? Swapping p and 1-p and swapping result with -result?

suntzuisafterU avatar Jan 22 '20 17:01 suntzuisafterU

When you put p=1-p at the beginning and return resultinstead, you get a different result, so that's not how that works. strangely enough I tested this a while ago and if I recall correctly, the current version does give the same result as when you fit in R ... How is that possible?

PDiracDelta avatar Jan 23 '20 09:01 PDiracDelta