Last active
November 7, 2021 17:17
-
-
Save PDiracDelta/98585ce0e8c62673bf13c1843f2f7215 to your computer and use it in GitHub Desktop.
Python3 log likelihood of Negative Binomial for binned data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def log_likelihood_binned(params, *args): | |
r, p = params | |
occurrences_binned = args[0] | |
observed_values = np.arange(len(X_binned)) | |
N = np.sum(occurrences_binned) | |
result = np.sum(np.multiply(occurrences_binned, gammaln(observed_values + r))) \ | |
- np.sum(np.multiply(occurrences_binned, np.log(factorial(observed_values)))) \ | |
- N * (gammaln(r)) \ | |
+ np.sum(np.multiply(occurrences_binned, observed_values * np.log(1 - (p if p < 1 else 1 - infinitesimal)))) \ | |
+ N * r * np.log(p) | |
return -result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment