Debian Codegraph @

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

raw
1 function [imfpdf,imfpo,imfprob] = fn_histpdfcnt(imfcnt,ndrawscnt,imfloor,hbin,ninv,...
2 gIndx,ncom,kIndx,lval,hval)
3 % [imfpdf,imfpo,imfprob] = fn_histpdfcnt(imfcnt,ndrawscnt,imfloor,hbin,ninv,gIndx,ncom,kIndx,lval,hval)
4 % From already ordered and binned (cnt: count) series (not pdf yet).
5 % Produce (1) the dataset for generating p.d.f.;
6 % (2) the dataset for probability (NOT density) at each bin;
7 % (3) with option gIndx=1, graph density functions.
8 %
9 % imfcnt: 2+ninv-by-k. Counted structural parameters, qmygcnt, ygcnt, or impulse responses.
10 % ndrawscnt: a total number of draws used in imfcnt
11 % imfloor: k-element vector of low values of imf but imf_h can be below "imfloor" and above "imceiling"
12 % hbin: k-element vector of bin lengths = (imceilling-imfloor)/ninv. Need not be a 1-by-k row vector.
13 % ninv: the number of bins (small interior intervals) between ``imfloor'' and ``imfceiling''
14 % gIndx: 1: plot graphs of pdf's; 0: no plot.
15 % If gIndx=0, ncom, kIndx, lval, and hval are irrelevant and no densities will be plotted.
16 % ncom: number of combined intervals. Large ncom implies large size of the bin.
17 % Must set ncom so that ninv can be divided
18 % kIndx: index for selected variables. Length(kIndx)<=k.
19 % If kIndx=[], lval and hval are irrelevant and no densities will be plotted.
20 % lval: length(kIndx)-element vector of the lowest values on the axis;
21 % The vector corresponds to kIndx. This option is disenabled by setting it to [].
22 % hval: length(kIndx)-element vector of the highest values on the axis;
23 % The vector corresponds to kIndx. This option is disenabled by setting it to [].
24 %-----------------
25 % imfpdf: 2+ninv-by-k. Density (NOT probability)
26 % imfpo: 2+ninv-by-k. Bin position (x-axis) in relation to imfs3
27 % imfprob: 2+ninv-by-k. Probability (NOT density) at each bin
28 %
29 % 27 August 1998 Tao Zha
30 % Revised, October 1998, March 1999, August 2000.
31 %
32 % Copyright (C) 1997-2012 Tao Zha
33 %
34 % This free software: you can redistribute it and/or modify
35 % it under the terms of the GNU General Public License as published by
36 % the Free Software Foundation, either version 3 of the License, or
37 % (at your option) any later version.
38 %
39 % It is distributed in the hope that it will be useful,
40 % but WITHOUT ANY WARRANTY; without even the implied warranty of
41 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 % GNU General Public License for more details.
43 %
44 % If you did not received a copy of the GNU General Public License
45 % with this software, see <http://www.gnu.org/licenses/>.
46 %
47
48
49 if (nargin==5), gIndx=0; end
50 if (nargin==8), lval=[]; hval=[]; end
51
52 imfloor=imfloor(:); hbin=hbin(:);
53 k=size(imfcnt,2);
54 invlengthM = repmat(hbin',[2+ninv,1]);
55 %invlengthM([1 2+ninv],:) = 1; % August 2000. I comment this out because it leads to an extorted picture
56 % when the rest of invlengthM is much smaller or larger than 1.
57 % For the first interval (-inf, low bound) and last interval (high bound, +inf),
58 % the length is set at 1. Of course, theoretically, the interval length should be set
59 % to infinity. Adjust low and high bounds if 1 is not large enough compared with hbin.
60 imfprob = imfcnt ./ ndrawscnt; % probability (NOT density)
61 imfpdf = imfprob ./ invlengthM; % density
62
63 imfpo = [1:2+ninv]'; % positions for each forecast
64 imfpo = imfpo - 2; % the first step to put back to original form
65 imfpo = repmat(imfpo,[1,k]);
66 imfloorM = repmat(imfloor',[2+ninv,1]);
67 imfpo = (imfpo .* invlengthM) + imfloorM; % 2+ninv-by-k
68 % the final step to put back to original form of impulse responses
69
70 if gIndx
71 if mod(ninv,ncom)
72 warning('Set ncom so that ninv can be divided')
73 return
74 end
75 %
76 ninv2=ninv/ncom;
77 imfpdfn=zeros(2+ninv2,size(imfcnt,2)); %<<>>
78 imfpon=imfpdfn;
79 %
80 for ik=1:ninv2 % from 2 to 1+ninv2 for imfpdfn and imfpon
81 imfpdfn(1+ik,:) = sum(imfpdf(1+(ik-1)*ncom+1:1+ik*ncom,:))/ncom;
82 imfpon(1+ik,:) = mean(imfpo(1+(ik-1)*ncom+1:1+ik*ncom,:));
83 end
84
85 ck1=0;
86 for k1=kIndx
87 ck1=ck1+1;
88 figure
89 plot(imfpon(2:1+ninv2,k1),imfpdfn(2:1+ninv2,k1)) % do not plot the values at -infty and +infty
90 if ~isempty(lval) & ~isempty(hval)
91 set(gca,'XLim',[lval(ck1) hval(ck1)])
92 end
93 grid
94 end
95 end