# what is wrong in my code for calculate parameters bivariate distribution?

data is i,j as x, y as in pic

 i = {42, 180, 35, 392, 63, 230, 112, 281, 42, 28, 42, 120, 148, 16, 310, 28, 68, 336, 21.5, 50, 19, 30, 12, 120, 140, 170, 17, 115, 31, 21, 52, 164, 225, 225, 151, 60, 200, 46, 210, 14};
j = {4.5, 27, 19, 30.4, 28, 50, 7, 30, 3.5, 50, 6, 10.4, 20, 3.9, 41, 9, 7.6, 46, 2.6, 24, 3.2, 2, 5, 6.5, 12, 20.2, 13, 27, 18, 4.7, 9.8, 29, 7, 6, 20, 45, 7.5, 2.3, 24, 3};


Such that θ =( α , λ 1, λ 2,a,b), MLEs are gotten by maximizing equation

It cannot be acquired explicitly. We want to solve ﬁve nonlinear equations to compute MLEs, then we must use real data for get the values of the unknown parameters.

i write code as this

I1 = Total[
log[1 \[Minus] \[Alpha] (1 \[Minus] e \[Minus] \[Lambda]1 (i \[Minus] a)) (1 \[Minus] e \[Minus] \[Lambda]2 (j \[Minus] b))]];

I2 = (\[Alpha] \[Minus] 2) Total[
log[1 \[Minus] (1 \[Minus]
e \[Minus] \[Lambda]1 (i \[Minus] a)) (1 \[Minus]
e \[Minus] \[Lambda]2 (j \[Minus] b))]];

Maxlik = nlog[\[Alpha]\[Lambda]1\[Lambda]2] \[Minus] \[Lambda]1Sum[(i \
\[Minus] a), {i, {42, 180, 35, 392, 63, 230, 112, 281, 42, 28, 42,
120, 148, 16, 310, 28, 68, 336, 21.5, 50, 19, 30, 12, 120,
140, 170, 17, 115, 31, 21, 52, 164, 225, 225, 151, 60, 200,
46, 210, 14}}] \[Minus] \[Lambda]2Sum[(j \[Minus]
b), {j, {4.5, 27, 19, 30.4, 28, 50, 7, 30, 3.5, 50, 6, 10.4,
20, 3.9, 41, 9, 7.6, 46, 2.6, 24, 3.2, 2, 5, 6.5, 12, 20.2, 13,
27, 18, 4.7, 9.8, 29, 7, 6, 20, 45, 7.5, 2.3, 24, 3}}] + I1 +
I2;

Dbalfa = D[Maxlik, \[Alpha]];
Dblambda1 = D[Maxlik, \[Lambda]1];
Dblambda2 = D[Maxlik, \[Lambda]2];
Dba = D[Maxlik, a];
Dbb = D[Maxlik, b];

FindRoot[{Dbalfa == 0, Dblambda1 == 0, Dblambda2 == 0, Dba == 0, Dbb == 0}, {{\[Alpha], .047}, {\[Lambda]1, .1}, {\[Lambda]2, .3}, \{a, 12}, {b, 10}}]


i get this no result

• Mathematica is violently case sensitive. So it is Log and not log and it is E and not e (unless you have desktop published Euler's constant.) And, unless you have some missing code, Your Total syntax is wrong. n hasn't been given any value. Your i in your I1 and I2 doesn't seem to have a value. Just as an experiment, instead of FindRoot just display {Dbalfa==0,Dblambda1==0,Dblambda2==0,Dba==0,Dbb==0} and look at it and see all the variables that don't have values. Put * inside nlog and inside \[Lambda]1Sum and inside \[Lambda]2Sum Please fix all those now. THanks
– Bill
Commented Aug 10, 2022 at 19:23
• You need to post code without syntax errors. log should be Log, nlog[\[Alpha]\[Lambda]1\[Lambda]2] should be n Log[\[Alpha] \[Lambda]1 \[Lambda]2], etc. You've had other questions with this same issue.
– JimB
Commented Aug 10, 2022 at 19:42
• Would you post a link to the reference (article or book) for Table 1 and the log of the likelihood?
– JimB
Commented Aug 10, 2022 at 21:04
• It's Truncated Bivariate Kumaraswamy Exponential Distribution dx.doi.org/10.18576/jsap/110208 Commented Aug 10, 2022 at 21:22
• Thank you! That explains a lot. For those considering helping with this question, the Mathematica code is given in the appendix of the journal article. But that appendix is not formatted properly and results in what you see above.
– JimB
Commented Aug 10, 2022 at 21:32

The Mathematica code above is from the appendix of https://www.naturalspublishing.com/files/published/p6x2vhc2x96687.pdf but unfortunately it is not formatted properly to import directly into Mathematica.

I have made changes in the code for two reasons: (1) To fix formatting errors and (2) because the maximum likelihood estimates do not result in all of the derivatives of the log of the likelihood being zero.

Issue (2) is because the maximum likelihood estimates of parameters $$a$$ and $$b$$ are the respective minimums of the datasets: Min[i] and Min[j]. In such cases the derivatives of the log of the likelihood won't be zero for those parameters.

Below is what I think is the appropriate code using FindMaximum rather than FindRoot.

(* Data *)
i = {42, 180, 35, 392, 63, 230, 112, 281, 42, 28, 42, 120, 148, 16,
310, 28, 68, 336, 21.5, 50, 19, 30, 12, 120, 140, 170, 17, 115, 31,
21, 52, 164, 225, 225, 151, 60, 200, 46, 210, 14};
j = {4.5, 27, 19, 30.4, 28, 50, 7, 30, 3.5, 50, 6, 10.4, 20, 3.9, 41,
9, 7.6, 46, 2.6, 24, 3.2, 2, 5, 6.5, 12, 20.2, 13, 27, 18, 4.7,
9.8, 29, 7, 6, 20, 45, 7.5, 2.3, 24, 3};
n = Length[i];

(* Construct log of the likelihood *)
I1 = Total[Log[1 - α (1 - Exp[-λ1 (i - a)]) (1 - Exp[-λ2 (j - b)])]];
I2 = (α - 2) Total[Log[1 - (1 - Exp[-λ1 (i - a)]) (1 - Exp[-λ2 (j - b)])]];
logL = n Log[α λ1 λ2] - λ1 Total[i - a] - λ2 Total[j - b] + I1 + I2;

(* Maximum likelihood estimates *)
mle = FindMaximum[{logL /. a -> Min[i] /. b -> Min[j], {λ1 > 0, λ2 > 0}},
{{α, .047}, {λ1, .1}, {λ2, .3}}]
(* {-366.874, {α -> 0.549173, λ1 -> 0.0173524, λ2 -> 0.123608}} *)