Debian Codegraph @

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

raw
1 function [imfl,imfh,imfl1,imfh1, imfmedian] = demarw(xpo,xprob)
2 % [imfl,imfh,imfl1,imfh1] = fn_demarw(xpo,xprob)
3 % Demarcate the .68 and .90 error bands given positions and properly scaled probabilities (weights).
4 % Calls fn_histwpdfg() first.
5 %
6 % xpo: ndraws-by-n. Centered position
7 % xprob: ndraws-by-n. Must be properly scaled probabilities corresponding to xpo.
8 %-----------------
9 % imfl: lower .90 bound, n-by-1
10 % imfh: higher .90 bound, n-by-1
11 % imfl1: lower .68 bound, n-by-1
12 % imfh1: higher .68 bound, n-by-1
13 % imfmedian: .50 estimate, n-by-1.
14 %
15 % Note: fn_histwpdfg() must be called first to get xpo and xprob.
16 % August 1999 Tao Zha; Revised, August 2000
17 %
18 % Copyright (C) 1997-2012 Tao Zha
19 %
20 % This free software: you can redistribute it and/or modify
21 % it under the terms of the GNU General Public License as published by
22 % the Free Software Foundation, either version 3 of the License, or
23 % (at your option) any later version.
24 %
25 % It is distributed in the hope that it will be useful,
26 % but WITHOUT ANY WARRANTY; without even the implied warranty of
27 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 % GNU General Public License for more details.
29 %
30 % If you did not received a copy of the GNU General Public License
31 % with this software, see <http://www.gnu.org/licenses/>.
32 %
33
34
35 [ndraws,n]=size(xpo);
36
37 %$$$ .68 and .95 probability bands
38 imfl = zeros(n,1); % preallocating
39 imfh = zeros(n,1); % preallocating
40 imfl1 = zeros(n,1); % preallocating
41 imfh1 = zeros(n,1); % preallocating
42 imfmedian = zeros(n,1); % preallocating
43 imfpo = zeros(4,n); % 4 positions: l,h,l1,h1.
44 %
45 %tic
46 tem = cumsum(xprob); % cumulative probability
47 tem = tem .* 100;
48 %
49 %@@@ the following operations are valid only because tem are increasing!
50 for k = 1:n
51 %
52 %@@@ the following operations are valid only because tem are increasing!
53 %** 5% low tail
54 if isempty(max(find(tem(:,k)<5)))
55 imfl(k) = xpo(1,k);
56 else
57 imfl(k) = xpo(max(find(tem(:,k)<5)),k);
58 end
59 %** 16% low tail
60 if isempty(max(find(tem(:,k)<16)))
61 imfl1(k) = xpo(1,k);
62 else
63 imfl1(k) = xpo(max(find(tem(:,k)<16)),k);
64 end
65 %** 50% estimate
66 if isempty(max(find(tem(:,k)<50)))
67 imfmedian(k) = xpo(1,k);
68 else
69 imfmedian(k) = xpo(max(find(tem(:,k)<50)),k);
70 end
71 %** 5% high tail
72 imfh(k) = xpo(min(find(tem(:,k)>95)),k);
73 %** 16% low tail
74 imfh1(k) = xpo(min(find(tem(:,k)>84)),k);
75 end