Errors in Estimating Parameters With MLE and fsolve

3 views (last 30 days)
Hi, I am trying to estimate parameters of a distribution using mle, these are the objective functions
and in code (file name : sumbgg)
function F = sumbgg(p,x)
sum1 = 0;
sum2 = 0;
sum3 = 0;
sum4 = 0;
sum5 = 0;
sum6 = 0;
sum7 = 0;
sum8 = 0;
sum9 = 0;
sum10 = 0;
n = length(x);
for i = 1:n
e = exp(p(3) * x(i));
d = exp(-p(2) / p(3) * (e - 1));
c = 1 - d;
b = exp(p(3) * x(i) - 1);
a = c^p(1);
sum1 = sum1 + log(c);
sum2 = sum2 + a * log(c) / log(1 - a);
sum3 = sum3 + e;
sum4 = sum4 + b * d / c;
sum5 = sum5 + b * d / c * a / (1 - a);
sum6 = sum6 + x(i);
sum7 = sum7 + e * (1 - p(3)*x(i));
sum8 = sum8 + d * (p(3)*x(i) * e + e + 1) / c;
sum9 = sum9 + (a * d) * (p(3) * x(i) * e + e + 1) / (1 - a);
sum10 = sum10 + log(1 - a);
end
p3_2 = p(3)^2;
F = [n / p(1) + p(4) * sum1 - (p(5) - 1) * sum2;
n / p(2) + n / p(3) - 1 / p(3) * sum3 + ...
(p(1) * p(4) - 1) / p(3) * sum4 + p(1) * (p(5) - 1) / p(3) * sum5;
-n * p(2) / p3_2 + sum6 + p(2) * sum7 / p3_2 - ...
p(2) * (p(4) * p(1) - 1) * sum8 / p3_2 + ...
p(1) * p(2) * (p(5) - 1) * sum9 / p3_2;
-n * (psi(p(4)) + psi(p(4) + p(5))) + p(1) * sum1;
-n * (psi(p(4)) + psi(p(4) + p(5))) + p(1) * sum10];
F = double(F);
end
Then to find the parameters I used this code (filename: calc)
p = [];
x = [0.1, 0.2, 1, 1, 1, 1, 1, 2, 3, 6, 7, 11, 12, 18, 18, 18, 18, 18,...
21, 32, 36, 40, 45, 46, 47, 50, 55, 60, 63, 63, 67, 67, 67, 67, ...
72, 75, 79, 82, 82, 83, 84, 84, 84, 85, 85, 85, 85, 85, 86, 86];
p0 = [2 0.01 0.05 0.11 0.01];
i = 1;
options = optimoptions('fsolve');
p = fsolve(@(p)sumbgg(p,x), p0, options);
fprintf(p)
it then returned this error some errors such as
I have tried to fix it but nothing seems to work. Any suggestions for the problem I have or alternatives to using the code above? Thank you.
  3 Comments
Natasha Davina
Natasha Davina on 10 Jun 2022
@Torsten both a and b has to be nonnegative in my model. I am confused with the "X must be nonnegative" error message because all my x has a non negative value.
Torsten
Torsten on 10 Jun 2022
a and b change in the course of the iteration since they are adjustable parameters.
Include the line
p(4:5) = p(4:5).^2
after the line
function F = sumbgg(p,x)
Remember that you will have to change the line
p0 = [2 0.01 0.05 0.11 0.01];
to
p0 = [2 0.01 0.05 sqrt[0.11,0.01]];
and the fitted paramters obtained
p = fsolve(@(p)sumbgg(p,x), p0, options);
to
p(4:5) = p(4:5).^2

Sign in to comment.

Answers (0)

Categories

Find more on Sensitivity Analysis 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!