I am trying to create a simple mle example by writing a negative log likelihood function, assuming a normal distribution, and use fminsearch to find the estimates. However, I am struggling to get fminsearch to allow a second input. Specifically, if I write the following function (the normal log likelihood function excluding sigma):
function L = likelihoodfunc(B) load myvars.mat L = (n/2)*log(2*pi)+0.5*(y-X*B)'*(y-X*B); %negative log-likelihood
Everything runs fine and my fminsearch returns estimates for B. However, I cannot figure out how to include sigma. The normal log likelihood function should read:
L = (n/2)*log(2*pi*sig^2)+0.5*(1/sig^2)*(y-X*B)'*(y-X*B)
Can fminsearch be used here, or should I be using a different feature?