Alex
Alex

Reputation: 119

Maximizing Likelihood, Julia

I have a log-likelihood function and I want to maximize it in respect to theta (N), and it is defined as:

 function loglik(theta,n,r)
    N=theta;k=length(n);
    ar1=float(lgamma(N+1));ar2=sum(n)*log(sum(n)/(k*N));ar3=(k*N-sum(n))*log(1-(sum(n))/(k*N));
    par=float(lgamma((N-r)+1));
    return(-(ar1+ar2+ar3-par)) end

The I use Optim.jl's optimize function as:

   r=optimize(b->loglik(b,nn, 962), 978, BFGS() ); 

Where nn is an array. And I get this error:

   ERROR:MethodError no method matching optimize (::#46#47,::Float64, ::Optim.BFGS)

Can anyone help?

Upvotes: 2

Views: 500

Answers (1)

pkofod
pkofod

Reputation: 774

You're almost there! You need to initialize it with an array.

optimize(b->loglik(first(b),nn,962), [978.,], BFGS())

(though you still need to provide us with nn for this answer to show the output)

edit: since b is a scalar in loglik, I changed it to b->loglik(first(b),nn, 962) as suggested by Chris Rackauckas below.

Upvotes: 3

Related Questions