| 1 |
function [pabove,pbelow]=sbcontest(xinput) |
| 2 |
% [pabove,pbelow]=sbcontest(xinput) |
| 3 |
% Small Sample Bayesian Contour Test (sbcontest) for overidentified models |
| 4 |
% |
| 5 |
% xinput{1}: idenmlh -- handle for the file idenml.mat |
| 6 |
% xinput{2}: SpHUouth -- handle for the file sphuout.mat |
| 7 |
% xinput{3}: fss -- effective sample size == nSample-lags+# of dummy observations |
| 8 |
% xinput{4}: imndraws=nstarts*ndraws2 |
| 9 |
% xinput{5}: nvar -- # of endogenous variables |
| 10 |
% xinput{6}: nbuffer -- interval of whcih for printing, plotting, saving, etc. |
| 11 |
%-------------- |
| 12 |
% pabove: probablity of the reduced-form LH value above the overidentified LH peak value |
| 13 |
% pbelow: probablity of the reduced-form LH value below the overidentified LH peak value |
| 14 |
% |
| 15 |
% Copyright (C) 1997-2012 Tao Zha |
| 16 |
% |
| 17 |
% This free software: you can redistribute it and/or modify |
| 18 |
% it under the terms of the GNU General Public License as published by |
| 19 |
% the Free Software Foundation, either version 3 of the License, or |
| 20 |
% (at your option) any later version. |
| 21 |
% |
| 22 |
% It is distributed in the hope that it will be useful, |
| 23 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 |
% GNU General Public License for more details. |
| 26 |
% |
| 27 |
% If you did not received a copy of the GNU General Public License |
| 28 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 29 |
% |
| 30 |
|
| 31 |
idenmlh = xinput{1}; SpHUouth = xinput{2}; fss = xinput{3}; imndraws = xinput{4}; nvar = xinput{5}; |
| 32 |
nbuffer = xinput{6}; |
| 33 |
|
| 34 |
neqn = nvar; %<<>> number of equations |
| 35 |
eval(['load ' idenmlh]); |
| 36 |
eval(['load ' SpHUouth]); |
| 37 |
|
| 38 |
pabove=0; |
| 39 |
pbelow=0; |
| 40 |
load idenml % fhat at ML for identified version |
| 41 |
fhat=-fhat; |
| 42 |
% this value is strictly smaller than that at the peak of reduced-form LH |
| 43 |
disp('If you havent run idenml with Rform=1, you must do so now') |
| 44 |
disp('Press ctrl-c to abort now or any other key to continue') |
| 45 |
disp(' ') |
| 46 |
pause |
| 47 |
load SpHUout % this is the output file by running "idenml" with Rform=1 |
| 48 |
% with output SpHU |
| 49 |
SpHs = SpHU*fss; % for the Wishart draw |
| 50 |
SpHsc = chol(SpHs); % upper triangular where Sphsc' is |
| 51 |
% lower triangular Choleski, for Wishart draw |
| 52 |
tic |
| 53 |
for draws=1:imndraws |
| 54 |
if ~mod(draws,nbuffer) |
| 55 |
draws |
| 56 |
end |
| 57 |
ranw = randn(neqn,fss-neqn-1); |
| 58 |
ranw = SpHsc\ranw; % inv(SpHsc) is upper triagular Choleski of inv(SpHs) |
| 59 |
%ranw = SpHsic*ranw; |
| 60 |
% normal draws (T-nvar-1)*nvar, with variance inv(SpHs) (note, NOT inv(SpH)) |
| 61 |
sinh = ranw*ranw'; % Wishart draws for A0h*A0h' |
| 62 |
A0_h = chol2(sinh); % upper triangular Choleski |
| 63 |
a0indx = find(A0_h); |
| 64 |
|
| 65 |
xhat_h = A0_h(a0indx); |
| 66 |
jnk = a0lhfun(xhat_h,SpHU,fss,nvar,a0indx); |
| 67 |
fhat_h = -jnk; |
| 68 |
|
| 69 |
if fhat_h > fhat |
| 70 |
pabove = pabove+1; |
| 71 |
else |
| 72 |
pbelow = pbelow+1; |
| 73 |
end |
| 74 |
end |
| 75 |
timend=toc; |
| 76 |
timeminutes=timend/60 |
| 77 |
|
| 78 |
pabove = pabove/imndraws |
| 79 |
pbelow = pbelow/imndraws |