-------------------------------------------------------------------------------------- name: log: C:\Users\ehudes\Documents\My Documents on C\Methods Core\2015\20150213_To > r_Estie_MI_I\lem_mata.log log type: text opened on: 30 Jan 2015, 17:06:15 . . // 2 by 2 table, missing values on one margin. . // same example as solved by LEM . // the SV matrix (col vector) includes the . // 4 (s,v) joint probabilities and 2 marginal (s,.) . // p is the col vector of 4 joint probabilities Pr(S=s, V=v) . // C is the row vector to multiply p; c is the element 1 . // We impose the constraint C p = c, that is, the 4 probabilities add up to 1 . // Cc is the row vector that is passed to Mata . . mata: // start Mata ------------------------------------------------- mata (type end to exit) ------------ : : mata clear : SV = (28, 45, 22, 52 , 10, 15)' : C = (1, 1, 1, 1) : c = (1) : Cc = (C,c) : void myfun(todo, p, SV, lnf, g, H) > { > lnf = SV[1]*log(p[1]) + SV[2]*log(p[2]) /// > + SV[3]*log(p[3]) + SV[4]*log(p[4]) > > lnf = lnf + SV[5]*log(p[1]+p[2]) /// > + SV[6]*log(p[3]+p[4]) > } note: argument todo unused note: argument g unused note: argument H unused : : S = optimize_init() : : optimize_init_evaluator(S, &myfun()) // optimize liklihood function : optimize_init_params(S, (.25, .25, .25, .25)) // initial values of p : optimize_init_constraints(S, Cc) // constraints : optimize_init_argument(S, 1, SV) : optimize(S) Iteration 0: f(p) = -221.11395 Iteration 1: f(p) = -212.96626 Iteration 2: f(p) = -212.75194 Iteration 3: f(p) = -212.75185 Iteration 4: f(p) = -212.75185 1 2 3 4 +---------------------------------------------------------+ 1 | .1850908096 .297467338 .1538340669 .3636077855 | +---------------------------------------------------------+ : optimize_result_V_oim(S) 1 2 3 4 +-------------------------------------------------------------+ 1 | .0009678019 -.000410978 -.0001655422 -.0003912817 | 2 | -.000410978 .0013058738 -.00026605 -.0006288459 | 3 | -.0001655422 -.00026605 .0008841929 -.0004526007 | 4 | -.0003912817 -.0006288459 -.0004526007 .0014727284 | +-------------------------------------------------------------+ : : p = optimize(S) // estimated probabilities Iteration 0: f(p) = -212.75185 Iteration 1: f(p) = -212.75185 : varcov_p = optimize_result_V_oim(S) // var-cov matrix of estimates : var_p = diagonal(varcov_p) // variances of estimates : se_p = sqrt(var_p) // se's of estimates : : round(p, .0001) // print out estimated probabilities w/ 4 decimals 1 2 3 4 +---------------------------------+ 1 | .1851 .2975 .1538 .3636 | +---------------------------------+ : round(se_p', .0001) // print out row of estimated se's w/ 4 decimals 1 2 3 4 +---------------------------------+ 1 | .0311 .0361 .0297 .0384 | +---------------------------------+ : : end // exit Mata -------------------------------------------------------------------------------------- . . log close name: log: C:\Users\ehudes\Documents\My Documents on C\Methods Core\2015\20150213_To > r_Estie_MI_I\lem_mata.log log type: text closed on: 30 Jan 2015, 17:06:15 --------------------------------------------------------------------------------------