全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Gauss专版
2106 1
2014-11-13
我在看Hamilton(2001)给出的一种非线性方程的估计方法时,我用我自己 的数据做时,再利用BFGS算法求解MLE估计量时,总提示矩阵不正定,想请问大家这是什么原因?我把BFGS算法估计MLE部分的代码附后:
/* ===========================================================
             FIND MAXIMUM LIKELIHOOD ESTIMATES, IF DESIRED
=============================================================*/

kc = 1;
if kmle == 1;    @ this starts the MLE section @

/* ------------------------------------------------------------------------------------------------------------------------
   === SET STARTING VALUES FOR NUMERICAL OPTIMIZATION === */

th0 = ( 1./(sigx*sqrt(k)) ) | 0.5;
th0';


@ thx = 0.084 | 0.001 | 1.85 ; h = eye(k+1); i = 1; psi = zeros(1,k+2); goto jump4;  @

proc startval;     @ This defines starting value for iteration to be th @
  retp(th0); endp;

/* -----------------------------------------------------------------------------------------------------------------------------
   === SET GLOBAL CONTROL PARAMETERS FOR NUMERICAL
          OPTIMIZATION === */

     #include optmum.ext;
      _opalgr = 2;    @ This chooses BFGS optimization  @
      _opmiter = 150;  @ This controls the maximum number of iterations @
      _opshess = (1.e-4)*eye(k+1);

/* -----------------------------------------------------------------------------------------------------------------------------
   === CALL GAUSS PROCEDURES FOR NUMERICAL OPTIMIZATION === */

        kc=1;
        {thx,f,g,h} =optmum(&conc,startval);

"";"";"Final results";"MLE as parameterized for numerical optimization ";
"Coefficients:";thx';
"";"Value of log likelihood:";;-f;
"";"Gradient vector:";g';

"==================================";
kc = 2;
call conc(thx);

/* ------------------------------------------------------------------------------------------------------------------------
   === CALCULATE STANDARD ERRORS === */
kc = 3;
ks = 0;
thmore = conc(thx);

kc = 1;
g = gradp(&full,thx|thmore);
"";"Numerically calculated gradient:";g;
"";"";
h = (hessp(&full,thx|thmore));
   va = eigrs(h);
   if minc(eigrs(h)) <= 0;
        "Negative of Hessian is not positive definite";
        "Either you have not found local maximum, or else estimates are up "
        "against boundary condition.  In latter case, impose the restricted "
        "params rather than estimate them to calculate standard errors";
    else;
       h = invpd(h);
       std = diag(h)^.5;
       "For vector of coefficients parameterized as follows,";(thx | thmore)';
       "the standard errors are";std';
    endif;
"variance covariance matrix is";
format /m3;
h;
format /m1;
h;


/* -------------------------------------------------------------------------------------------------------------------------
   === GRAPH FUNCTIONS OF INTEREST === */

_pgrid = 3 | 0;


if kex == 1;
  @ plot figure 1 for MLE @
      _ptek = "graph1ml.tkf";
      title("Figure 1 (MLE)");
      call graph1dim(2,2,xbar);
      chis = conc(thx);
      xy(xs[.,2],chis);

elseif kex == 2;
      _ptek = "graph2ml.tkf";
      title("Figure 2 (MLE)");
      call graph1dim(2,2,xbar);
      chis = conc(thx);
      xy(xs[.,6],chis);
endif;


endif;    @ this ends the MLE section @


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-11-13 13:26:47
太复杂,看不懂啊
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群