Finding the maximum likelihood estimates ?

4 views (last 30 days)
Apurva Narayan
Apurva Narayan on 23 Apr 2013
I need to find the MLE estimates. My code is as below. It seems to give me the correct mean but incorrect variance.
function obj = kmlepdf(x,y)
f1 = -1*50*log(2*pi*(y(2)));
f2 = ((y(2)));
f3 = ((x-y(1)).^2);
obj = (f1 + sum(0.5*(f3./f2))); % Normal Function
end
clear all;
load data;
y0 = [0.5 0.5];
lb = [0 0];
ub = [10 10];
% Assign Data to a new variable
x = data;
% Calling the Least Square Minimization
opts=optimset('DerivativeCheck','on','Display','off','TolX',1e-6,'TolFun',1e- 6,'Diagnostics','off','MaxIter',200);
[y, fval] = fmincon(@(y)kmlepdf(x,y),y0,[],[],[],[],lb,ub,[],opts)

Answers (1)

Tom Lane
Tom Lane on 24 Apr 2013
I believe you want
f1 = 0.5*length(x)*log(2*pi*(y(2)));
You start with 1/sqrt(2*pi*sigma^2), then take logs so you get a minus sign, but you need to negate again to get the negative log likelihood that you can minimize.
Also try setting lb(2)=eps.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!