Normal MLE using fminunc
Show older comments
Hi,
I am using the following code to estimate the MLE for the normal distribution.
1.load normaldata.dat
2.global x N
3.x = normaldata;
4.N = length(x);
5.theta0 = zeros(2,1);
6.[thetac,fval,output] = fminunc(@Norm,theta0);
7.thetac(2) = exp(thetac(2));
8.function output = NORM(theta)
9. global x N
10. theta(2) = exp(theta(2));
11. output = 0;
12.
13. for n = 1:N
14. output = output + (1/(2*theta(2)))*(-(x(n)-theta(1))^2);
15. end
16.
17. output = output - ((N/2)*(log(theta(2))));
18. output = -output;
19. end
It gives me the right answer, but I dont understand why we are setting sigma to exp(sigma) (refer to lines 7 and 10). Im guessing because we want sigma to be positive, in which case I understand why theta(2) = exp(theta(2)) in line 10 is present. But what is the relevance of theta(2) = exp(theta(2)) in line 7, surely it should be theta(2) = log(theta(2))???
Answers (0)
Categories
Find more on Descriptive Statistics 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!