I want to minimize the negative loglikelihood in order to approach an earlier calculated distribution as closely as possible. My distribution is a Beta-Binomial distribution and I need to pick the a (lpha) and b(eta) parameters. I based my function that calculates the negative loglikelihood on one of the answers of another topic.
def nll(a, b):
k = players['Goals'].sum() # equal to the number of successes
n = players['Shots'].sum() # equal to the number of trials
log = gammaln(n + 1) + gammaln(k + a) + gammaln(n - k + b) + gammaln(a + b) - (gammaln(k + 1) + gammaln(n - k + 1) + gammaln(a) + gammaln(b) + gammaln(n + a + b))
return -(np.exp(log))
Next, I want to minimize the loglikelihood. In R this can be done with the following script:
# maximum likelihood estimation
m <- mle(ll, start = list(alpha = 1, beta = 10),
method = "L-BFGS-B", lower = c(0.0001, 0.1))
ab <- coef(m)
I am trying to reproduce the R-script in Python as follows:
init_params = [1, 10] # This is equal to the start-argument in R
res = minimize(nll, x0=init_params, method='L-BFGS-B', options={'disp' : True, 'maxiter': 250})
Running this, yields the following error:
return function(*(wrapper_args + args)) TypeError: nll() missing 1 required positional argument: 'b'
What am I exactly doing wrong? I inserted b=10 right?