楼主: liguo_lin
6293 8

hamilton filter (gauss program) (data attached) [推广有奖]

  • 0关注
  • 0粉丝

本科生

34%

还不是VIP/贵宾

-

威望
0
论坛币
11091 个
通用积分
0.2400
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
379 点
帖子
21
精华
0
在线时间
134 小时
注册时间
2004-12-31
最后登录
2021-11-27

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

ks=1; output file=junk reset; capt = 204; @ capt is the sample size @ load bbbb[capt+1,2] = 2004.txt; bbbb=bbbb[.,2]; bbbb = bbbb[1:capt,1]~bbbb[2:capt+1,1]; y = 100*ln(bbbb[.,2]./bbbb[.,1]); y=y[1:200]; capt = rows(y); nth = 6; @ nth is the number of params to be estimated@ mu1 = 1; mu2 = 0; phi1 = .1; sig = 1; p11 = 3.5; p22 = 1.5; th = mu1|mu2|phi1|sig|p11|p22;

nk = 2; @ nk is the first observation for which the likelihood will be evaluated @ n = 4; @ n is the dimension of the state vector @ captst = capt - nk +1; @ captst is the effective sample size @ skif = zeros(captst,n); @ skif is the matrix of filtered probs @ skis = zeros(captst,n); @ skis is the matrix of smoothed probs @

let hp[4,4]= 1.0000 0.0000 1.0000 0.0000 0.0000 1.0000 0.0000 1.0000 1.0000 1.0000 0.0000 0.0000 0.0000 0.0000 1.0000 1.0000 ;

fm = zeros(4,4);

proc ofn(th); @ this proc evaluates filter probs and likelihood @ local ncount,mu,phi,sig,pm,eta,iz,chsi,it,f,fit,fx,hw,fj, ij,ap,const,pq,hk,ihk;

@ Convert parameter vector to convenient form @ mu = th[1:2,1]; phi = 1 | -th[3]; sig = th[4,1]*ones(n,1); if ks==2; sig=sig; pm=th[5 6]; elseif ks==1; sig = sig^2; pm = (th[5]^2/(1+th[5]^2))|th[6]^2/(1+th[6]^2); endif;

const = phi .*. mu; const = const'*hp;

@ Convert data to AR resids @ eta = y[nk:capt,1]; eta = eta ~y[1:capt-1,1]; eta = ((eta*phi - const)^2)./sig';

eta = (1./sqrt(sig')).*exp(-eta/2);

@ Calculate ergodic probabilities @

fm[1,1]=pm[1];fm[2,1]=1-pm[1]; fm[1,3]=pm[1];fm[2,3]=1-pm[1]; fm[3,2]=1-pm[2];fm[4,2]=pm[2]; fm[3,4]=1-pm[2];fm[4,4]=pm[2]; ap = (eye(n)-fm)|ones(1,n); chsi = sumc((invpd(ap'*ap)')); chsi = maxc(chsi'|zeros(1,n));

@ Filter iteration @ f = 0; it = 1; do until it > captst; fx = chsi .* eta[it,.]'; fit = sumc(fx); skif[it,.] = fx'/fit; f = f + ln(fit); chsi = fm*fx/fit; it = it+1; endo; retp(-f); endp; /*=========================================================================*/ @ Next call the GAUSS numerical optimizer @ output off; library optmum pgraph; optset; {x,f,g,h} =optmum(&ofn,th); output file=junk on;

"";"";"MLE as parameterized for numerical optimization "; "Coefficients:";x'; "";"Value of log likelihood:";;-f;

"";"Vector is reparameterized to report final results as follows"; "Means for each state:";x[1:2,1]'; "Autoregressive coefficients:";x[3]'; x[4] = x[4]^2; "Variances:";x[4]; x[5 6] = (x[5]^2/(1+x[5]^2))|x[6]^2/(1+x[6]^2);

ks = 2; h = (hessp(&ofn,x)); va = eigrs(h); call ofn(x); 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,";x'; "the standard errors are";std'; endif;

@ Calculate smoothed probs if desired @ if ks == 2; skis[captst,.] = skif[captst,.]; it = 1; do until it == captst; if minc(skif[captst-it,.]') > 1.e-150; skis[captst-it,.] = skif[captst-it,.].* ((skis[captst-it+1,.]./(skif[captst-it,.]*fm'))*fm); else; @ adjust code so as not to divide by zero @ hk = skif[captst-it,.]*fm'; ihk = 1; do until ihk > n; if hk[1,ihk] > 1.e-150; hk[1,ihk] = skis[captst-it+1,ihk]/hk[1,ihk]; else; hk[1,ihk] = 0; endif; ihk = ihk + 1; endo; skis[captst-it,.] = skif[captst-it,.].*(hk*fm); endif; it = it+1; endo; endif;

graphset; xy(seqa(53.5,.25,rows(skis)),skif[.,2]+skif[.,4]);

8779.txt (2.61 KB)
二维码

扫码加我 拉你入群

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

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

关键词:hamilton attached Program attach filter Data GAUSS Program filter attached

沙发
liguo_lin 发表于 2005-2-9 22:16:00 |只看作者 |坛友微信交流群
偶老师的课堂笔记,hamilton filter 很好的研究了1984年之前的经济波动,图形中的纵轴代表经济衰退的概率。但是1984年之后就不是特别好用。欧老师专门就此发表了一片文章认为是因为0存货的出现导致该filter不敏感。偶老师UCSD毕业师从hamilton

使用道具

藤椅
gloryfly 在职认证  发表于 2005-2-11 01:15:00 |只看作者 |坛友微信交流群
这个该顶一下~~
你们世俗的人都认为大侠是玉树临风的 难道 大侠就不能矮胖吗?

使用道具

板凳
haoqm 发表于 2005-2-20 22:08:00 |只看作者 |坛友微信交流群

run perfectly,thanks

使用道具

报纸
wikiki 发表于 2006-4-24 23:35:00 |只看作者 |坛友微信交流群

感謝

使用道具

地板
anneguo 发表于 2007-12-2 09:16:00 |只看作者 |坛友微信交流群
你老师是LinGang?

使用道具

7
zhangxim 发表于 2009-1-30 02:53:00 |只看作者 |坛友微信交流群

使用道具

8
zhangtao 发表于 2011-6-1 21:30:23 |只看作者 |坛友微信交流群
iteration:  24  
   algorithm: BFGS         step method: STEPBT
   function:  74.34015     step length:  1.00000      backsteps:  0  
--------------------------------------------------------------------------------
   param.      param. value     relative grad.
       1             0.9409            0.0000
       2            -0.8982            0.0000
       3             0.3264            0.0000
       4             0.7682            0.0001
       5             4.3668            0.0000
       6             0.8756            0.0000

MLE as parameterized for numerical optimization
Coefficients:
0.940918 -0.898241 0.326346 0.768180 4.366735 0.875688
Value of log likelihood:-74.340146
Vector is reparameterized to report final results as follows
Means for each state:
0.940918 -0.898241
Autoregressive coefficients:
0.326346
Variances:
0.590100
for vector of coefficients parameterized as follows,
0.940918 -0.898241 0.326346 0.590100 0.950170 0.434014
the standard errors are
0.115269 0.430187 0.103343 0.086397 0.029621 0.274405
那位朋友能说说,输出的这些结果是什么意思?

pqg7.bmp (522.97 KB)

pqg7.bmp

使用道具

9
zhaomn200145 发表于 2011-6-2 07:51:21 |只看作者 |坛友微信交流群
最好找到原作者的paper看看。

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-25 13:55