Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/smtplis.m

raw
1 function [Avhx,hAvhx,cJump] = smtplis(Avhx,hAvhx,tdf,cJump,scf,...
2 H_sr,nfp,Sbd,fss,nvar,a0indx)
3 %
4 % Straight Metropolis Algorithm for identified VARs
5 %
6 % Avhx: previous draw of parameter x in 1st (kept) sequence
7 % hAvhx: lh value of previous draw in 1st (kept) sequence
8 % tdf: degrees of freedom of the jump t-distribution
9 % cJump: old count for times of jumping
10 % scf: scale down factor for stand. dev. -- square root of covariance matrix H
11 % H_sr: square root of covariance matrix H in approximate density
12 % nfp: number of free parameters
13 % Sbd: S in block diagonal covariance matrix in asymmetric prior case
14 % fss: effective sample size, including # of dummy observations
15 % nvar: number of variables
16 % a0indx: index of locations of free elements in A0
17 %--------------
18 % Avhx: new draw of parameter x in 1st (kept) sequence
19 % hAvhx: lh value of new draw in 1st (kept) sequence
20 % cJump: new count for times of jumping
21 %
22 % December 1998 by Tao Zha
23
24 %
25 % Copyright (C) 1997-2012 Tao Zha
26 %
27 % This free software: you can redistribute it and/or modify
28 % it under the terms of the GNU General Public License as published by
29 % the Free Software Foundation, either version 3 of the License, or
30 % (at your option) any later version.
31 %
32 % It is distributed in the hope that it will be useful,
33 % but WITHOUT ANY WARRANTY; without even the implied warranty of
34 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 % GNU General Public License for more details.
36 %
37 % If you did not received a copy of the GNU General Public License
38 % with this software, see <http://www.gnu.org/licenses/>.
39 %
40
41 %** draw free elements Avh in A0 and hyperparameters from t-dist
42 Avhz1 = scf*H_sr*randn(nfp,1); % normal draws
43 csq=randn(tdf,1);
44 csq=sum(csq .* csq);
45 Avhz = Avhz1/sqrt(csq/tdf);
46
47 Avhy = Avhx + Avhz; % random walk chain -- Metropolis
48 % ** actual density, having taken log
49 hAvhy = a0asfun(Avhy,Sbd,fss,nvar,a0indx);
50 hAvhy = -hAvhy; % converted to logLH
51
52 mphxy = exp(hAvhy-hAvhx);
53
54 %** draw u from uniform(0,1)
55 u = rand(1);
56 Jump = min([mphxy 1]);
57 if u <= Jump
58 Avhx = Avhy;
59 hAvhx = hAvhy;
60 cJump = cJump+1;
61 end