| 1 |
function [probelow,valow,yhatmean] = probvalsec(yhatprob,yhatpo,ninv,forep,nvar,findex,... |
| 2 |
sindex,valix,prolix) |
| 3 |
% [probelow,valow,yhatmean] = probvalsec(yhatprob,yhatpo,ninv,forep,nvar,findex,... |
| 4 |
% sindex,valix,prolix) |
| 5 |
% |
| 6 |
% Probabilites (below) and values for selected variables and levels. |
| 7 |
% This program takes outputs from "histpdfcnt.m" which must be run first. |
| 8 |
% Compute (1) the probability of the x-value (such as FFR) that is below a level |
| 9 |
% prespecified by valix (e.g., probability of R below 5%); (2) the x-value |
| 10 |
% (such as median or .60 lower-tail value) below which the probability is at a level |
| 11 |
% prespecified by "prolix" (e.g., median when 0.50 is prespecified); (3) the mean |
| 12 |
% of the x-values (e.g., the mean of Pcm, M2, FFR, etc.). |
| 13 |
% |
| 14 |
% yhatprob: 2+ninv-by-forep*shockp(=1 here)*nvar. Probability (NOT density) at each bin |
| 15 |
% yhatpo: 2+ninv-by-forep*shockp(=1 here)*nvar. Bin position (x-axis) in relation to yhat |
| 16 |
% ninv: the number of bins which are small interior intervals on the x-axis |
| 17 |
% forep: forecast periods -- 1st dim (must be compatible with findex) |
| 18 |
% nvar: number of shocks or variables -- 2nd dim (must be compatible with sindex) |
| 19 |
% findex: index for sected forecast periods 1st dim (c.f., forep) |
| 20 |
% sindex: index for selected shocks or variables, 2nd dim (c.f., nvar) |
| 21 |
% valix: length(findex)-by-length(sindex). Selected values on the x-axis |
| 22 |
% prolix: length(findex)-by-length(sindex). Selected (below) probabilites |
| 23 |
%----------- |
| 24 |
% probelow: length(findex)-by-length(sindex). The probability of the x-value |
| 25 |
% (such as FFR) that is below a level prespecified by valix (e.g., |
| 26 |
% probability of R below 5%). |
| 27 |
% valow: length(findex)-by-length(sindex). The x-value (such as median or .60 |
| 28 |
% lower-tail value) below which the probability is at a level |
| 29 |
% prespecified by "prolix" (e.g., median when 0.50 is prespecified); |
| 30 |
% yhatmean: forep-by-nvar. The mean of forecasts of Pcm, M2, FFR, etc. |
| 31 |
% |
| 32 |
% 3/25/99 Tao A. Zha |
| 33 |
% |
| 34 |
% Copyright (C) 1997-2012 Tao Zha |
| 35 |
% |
| 36 |
% This free software: you can redistribute it and/or modify |
| 37 |
% it under the terms of the GNU General Public License as published by |
| 38 |
% the Free Software Foundation, either version 3 of the License, or |
| 39 |
% (at your option) any later version. |
| 40 |
% |
| 41 |
% It is distributed in the hope that it will be useful, |
| 42 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 43 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 44 |
% GNU General Public License for more details. |
| 45 |
% |
| 46 |
% If you did not received a copy of the GNU General Public License |
| 47 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 48 |
% |
| 49 |
|
| 50 |
|
| 51 |
yhatprob2=reshape(yhatprob,2+ninv,forep,nvar); |
| 52 |
yhatpo2=reshape(yhatpo,2+ninv,forep,nvar); |
| 53 |
% |
| 54 |
%** Mean |
| 55 |
yhatmean0 = sum(yhatprob.*yhatpo,1); |
| 56 |
yhatmean = reshape(yhatmean0,forep,nvar); |
| 57 |
% |
| 58 |
probelow=zeros(length(findex),length(sindex)); |
| 59 |
% probablity of the x-value that is below a specified level |
| 60 |
% E.g., probability of R below 5%. |
| 61 |
valow=probelow; |
| 62 |
% x-value for the probability that is below a specified level |
| 63 |
% E.g., median when 0.50 is specified. |
| 64 |
cumprob=cumsum(yhatprob2,1); % cumulative probabilities |
| 65 |
% |
| 66 |
count1=0; |
| 67 |
for k1=sindex % forecast variables (or shocks) |
| 68 |
count1=count1+1; |
| 69 |
count2=0; |
| 70 |
for k2=findex % forecast periods |
| 71 |
count2=count2+1; |
| 72 |
posix = max(find(yhatpo2(:,k2,k1)<valix(count2,count1))); |
| 73 |
% index for the position corr. to the x-value respeicied. |
| 74 |
if isempty(posix) |
| 75 |
probelow(count2,count1) = cumprob(1,k2,k1); |
| 76 |
else |
| 77 |
probelow(count2,count1) = cumprob(posix,k2,k1); |
| 78 |
end |
| 79 |
posix1 = max(find(cumprob(:,k2,k1)<prolix(count2,count1))); |
| 80 |
% index for the position corr. probability (below) specified. |
| 81 |
if isempty(posix1) |
| 82 |
valow(count2,count1) = yhatpo2(1,k2,k1); |
| 83 |
else |
| 84 |
valow(count2,count1) = yhatpo2(posix1,k2,k1); |
| 85 |
end |
| 86 |
end |
| 87 |
end |
| 88 |
|
| 89 |
|
| 90 |
|