Debian Codegraph @

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

raw
1 function [imfl,imfh,imfl1,imfh1] = demarcate(imfcnt,imndraws,forep,nvar,...
2 ninv,invc,Am)
3 % [imfl,imfh,imfl1,imfh1] = demarcate(imfcnt,imndraws,forep,nvar,...
4 % ninv,invc,Am)
5 % imfcnt: 2+ninv-by-forep*nvar. Counted logcnt, yhatqgcnt, or yhatCalygcnt.
6 % In the case of impulse responses, forep=imstp and nvar=nvar^2
7 % imndraws: total number of draws allocated to "imfcnt"
8 % forep: the number of forecast periods (for both impulse responses and forecasting)
9 % nvar: the number of variables.
10 % ninv: the number of small interior intervals for sorting.
11 % invc: 1-by-forep*nvar. Whole inverval lenghth from min to max for one of
12 % (yhat, yhatqg, or yhatCalyg)
13 % Am: 1-by-forep*nvar. Range5{i}(:,:,1) is lowest range for for one of
14 % (yhat, yhatqg, or yhatCalyg)
15 %-----------------
16 % imfl: lower .95 bound, forep-by-nvar
17 % imfh: higher .95 bound, forep-by-nvar
18 % imfl1: lower .68 bound, forep-by-nvar
19 % imfh1: higher .68 bound, forep-by-nvar
20 %
21 %
22 % Copyright (C) 1997-2012 Tao Zha
23 %
24 % This free software: you can redistribute it and/or modify
25 % it under the terms of the GNU General Public License as published by
26 % the Free Software Foundation, either version 3 of the License, or
27 % (at your option) any later version.
28 %
29 % It is distributed in the hope that it will be useful,
30 % but WITHOUT ANY WARRANTY; without even the implied warranty of
31 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 % GNU General Public License for more details.
33 %
34 % If you did not received a copy of the GNU General Public License
35 % with this software, see <http://www.gnu.org/licenses/>.
36 %
37
38
39
40
41 %$$$ .68 and .95 probability bands
42 imfl = zeros(forep*nvar,1); % preallocating
43 imfh = zeros(forep*nvar,1); % preallocating
44 imfl1 = zeros(forep*nvar,1); % preallocating
45 imfh1 = zeros(forep*nvar,1); % preallocating
46 imfpo = zeros(4,forep*nvar); % 4 positions: l,h,l1,h1.
47 %
48 %tic
49 tem = cumsum(imfcnt) ./ imndraws; % cumulative probability
50 tem = tem .* 100;
51 clear imfcnt
52
53 uptail1=5; % 2.5, interval
54 lowtail1=95; % 97.5
55
56 %t_cum = toc
57 %
58 %tic
59 %
60 %@@@ the following operations are valid only because tem are increasing!
61 for k = 1:forep*nvar
62 %
63 %@@@ the following operations are valid only because tem are increasing!
64 %** 2.5% low tail
65 if isempty(max(find(tem(:,k)<uptail1)))
66 imfpo(1,k) = 1;
67 else
68 imfpo(1,k) = max(find(tem(:,k)<uptail1));
69 end
70 %** 16% low tail
71 if isempty(max(find(tem(:,k)<16)))
72 imfpo(2,k) = 1;
73 else
74 imfpo(2,k) = max(find(tem(:,k)<16));
75 end
76 %** 2.5% high tail
77 imfpo(3,k) = min(find(tem(:,k)>lowtail1));
78 %** 16% low tail
79 imfpo(4,k) = min(find(tem(:,k)>84));
80 end
81
82 tem = imfpo';
83 %save outprob.txt tem -ascii
84 %
85
86 imfpo = imfpo - 2; % the first step to put back to original form
87 % * 2.5% low tail
88 imfs = ((imfpo(1,:) .* invc) ./ ninv) + Am;
89 % the final step to put back to original form of impulse responses
90 imfl = imfs';
91 % * 16% low tail
92 imfs = ((imfpo(2,:) .* invc) ./ ninv) + Am;
93 % the final step to put back to original form of impulse responses
94 imfl1 = imfs';
95 % * 2.5% high tail
96 imfs = ((imfpo(3,:) .* invc) ./ ninv) + Am;
97 % the final step to put back to original form of impulse responses
98 imfh = imfs';
99 % * 16% high tail
100 imfs = ((imfpo(4,:) .* invc) ./ ninv) + Am;
101 % the final step to put back to original form of impulse responses
102 imfh1 = imfs';
103 %
104 %e_t = toc
105
106
107 % *** write out final results
108 clear tem
109 imfl = reshape(imfl,forep,nvar);
110 imfh = reshape(imfh,forep,nvar);
111 imfl1 = reshape(imfl1,forep,nvar);
112 imfh1 = reshape(imfh1,forep,nvar);
113 %
114 %