-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathshowPAIdelta.m
268 lines (196 loc) · 7.14 KB
/
showPAIdelta.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
%% load em toolboxes
warning('off','MATLAB:handle_graphics:exceptions:SceneNode')
path(pathdef)
addpath matlabtoolbox/emtools/
addpath matlabtoolbox/emtexbox/
addpath matlabtoolbox/emgibbsbox/
addpath matlabtoolbox/emeconometrics/
addpath matlabtoolbox/emstatespace/
%% Initial operations
clear; close all; clc;
resultsdir = 'matPAI2020'; % '~/jam/lager/var2021-matfiles';
MODELTYPES = {'CONST-2020', 'SVOtmax20-2020', ...
'SVt-2020', 'SVOmax20-2020', 'SV-2020', 'SVnanO5-2020'};
doMedian = false;
doTitle = false;
doLags = false;
doEquations = false;
maxIntercept = 7;
maxLag1 = 30;
maxLagOTHER = 5;
for thism = 1 : length(MODELTYPES)
modeltype = MODELTYPES{thism};
mat = matfile(fullfile(resultsdir, sprintf('fredMD16-2021-04-censoredYields-%s-p12.mat', modeltype)));
wrap = [];
titlename = sprintf('PAIsinceCOVID-%s', modeltype);
if doMedian
titlename = strcat(titlename, '-median');
end
initwrap
%#ok<*UNRCH>
%% pull some objects
Tjumpoffs = mat.Tjumpoffs;
ydates = mat.ydates;
N = mat.N;
p = mat.p;
K = N*p + 1;
ncode = mat.ncode;
Ylabels = fredMDprettylabel(ncode);
%% settings
jumpoff0 = datenum(2020,1,1);
T0 = find(ydates == jumpoff0);
ndxT0 = find(Tjumpoffs == T0); % find to make matfile calls work
%% collect PAI
if ~doMedian
PAI0 = mat.PAImean(:,:,ndxT0);
PAI0se = mat.PAIstdev(:,:,ndxT0);
PAIdevs = (mat.PAImean(:,:,ndxT0+1:end) - PAI0) ./ PAI0se;
else
PAI0 = mat.PAImedian(:,:,ndxT0);
PAI0se = mat.PAIstdev(:,:,ndxT0);
PAIdevs = (mat.PAImedian(:,:,ndxT0+1:end) - PAI0) ./ PAI0se;
end
maxRED = 2.5;
%% plot PAI
maxZ = ceil(max(abs(PAIdevs),[], 'all') * 10) / 10;
PAIdevs2D = reshape(PAIdevs(1:K,:,:), N * K, size(PAIdevs,3));
thisfig = figure;
hb = surf(ydates(T0+1:end),1:N*K,abs(PAIdevs2D)); %#ok<NASGU>
zlim([0 maxZ])
caxis([0 maxRED])
datetick('x')
xlabel('end of estimation window')
ylabel('parameters')
% color by height
shading interp
colorbar
colormap turbo
set(gca, 'fontsize', 12)
wrapthisfigure(thisfig, sprintf('PAIall-%s', modeltype), wrap);
%% plot PAI per equation
if doEquations
for n = 1 : N
maxZ = ceil(max(abs(PAIdevs),[], 'all') * 10) / 10;
thisfig = figure;
hb = surf(ydates(T0+1:end),1:K,squeeze(abs(PAIdevs(1:K,n,:)))); %#ok<NASGU>
zlim([0 maxZ])
caxis([0 maxRED])
datetick('x')
xlabel('end of estimation window')
ylabel('parameters')
% color by height
shading interp
colorbar
colormap turbo
wrapthisfigure(thisfig, sprintf('PAI-%s-%s', ncode{n}, modeltype), wrap, [], [], [], [], true);
if doTitle
title(sprintf('%s equation', Ylabels{n}))
wrapthisfigure(thisfig, sprintf('PAI-%s-%s-WITHTITLE', ncode{n}, modeltype), wrap);
end
end
end
%% plot intercepts per equation
thisfig = figure;
thesedevs = squeeze(abs(PAIdevs(1,:,:)));
% find variables with largest devs
maxdev = max(thesedevs, [], 2);
[maxdev,ndx] = sort(maxdev, 'desc');
thesendx = sort(ndx(maxdev > 1.5));
hb = surf(ydates(T0+1:end),1:N,thesedevs);
zlim([0 maxIntercept])
caxis([0 maxRED])
datetick('x')
yticks(thesendx)
yticklabels(Ylabels(thesendx));
xlabel('end of estimation window')
% color by height
shading interp
colorbar
colormap turbo
wrapthisfigure(thisfig, sprintf('PAI-intercept-%s', modeltype), wrap, [], [], [], [], true);
if doTitle
title(sprintf('intercepts'))
wrapthisfigure(thisfig, sprintf('PAI-intercept-%s-WITHTITLE', modeltype), wrap);
end
%% plot lag1 per equation
thisfig = figure;
thesedevs = reshape(abs(PAIdevs(1+(1:N),:,:)), N * N, []);
% find variables with largest devs
% maxdev = max(thesedevs, [], 2);
% [maxdev,ndx] = sort(maxdev, 'desc');
% thesendx = sort(ndx(maxdev > 1.5));
hb = surf(ydates(T0+1:end),1:N*N,thesedevs);
zlim([0 maxLag1])
caxis([0 maxRED])
datetick('x')
yticks(1:N:N*N)
ylim([1 N*N])
yticklabels(Ylabels);
xlabel('end of estimation window')
% color by height
shading interp
colorbar
colormap turbo
wrapthisfigure(thisfig, sprintf('PAI-lag1-%s', modeltype), wrap, [], [], [], [], true);
if doTitle
title(sprintf('intercepts'))
wrapthisfigure(thisfig, sprintf('PAI-lag1-%s-WITHTITLE', modeltype), wrap);
end
%% plot other lags per equation
thisfig = figure;
thesedevs = reshape(abs(PAIdevs(1+N+1:end,:,:)), N * N * (p - 1), []);
% find variables with largest devs
% maxdev = max(thesedevs, [], 2);
% [maxdev,ndx] = sort(maxdev, 'desc');
% thesendx = sort(ndx(maxdev > 1.5));
hb = surf(ydates(T0+1:end),1:N*N * (p - 1),thesedevs);
zlim([0 maxLagOTHER])
caxis([0 maxRED])
datetick('x')
yticks(1:N:N*N)
ylim([1 N*N])
yticklabels(Ylabels);
xlabel('end of estimation window')
% color by height
shading interp
colorbar
colormap turbo
wrapthisfigure(thisfig, sprintf('PAI-lagOTHER-%s', modeltype), wrap, [], [], [], [], true);
if doTitle
title(sprintf('intercepts'))
wrapthisfigure(thisfig, sprintf('PAI-lagOTHER-%s-WITHTITLE', modeltype), wrap);
end
%% plot PAI per block of each equation
if doLags
for n = 1 : N
maxZ = ceil(max(abs(PAIdevs(:,n,:)),[], 'all') * 10) / 10;
for lag = 1 : p
ndxlag = 1 + N * (lag-1) + (1 : N);
thisfig = figure;
hb = surf(ydates(T0+1:end),1:N,squeeze(abs(PAIdevs(ndxlag,n,:)))); %#ok<NASGU>
zlim([0 maxZ])
caxis([0 maxRED])
datetick('x')
xlabel('end of estimation window')
% ylabel('parameters')
yticks(1:N)
yticklabels(Ylabels)
% color by height
shading interp
colorbar
colormap turbo
wrapthisfigure(thisfig, sprintf('PAI-%s-lag%d-%s', ncode{n}, lag, modeltype), wrap, [], [], [], [], true);
if doTitle
title(sprintf('%s equation, lag %d', Ylabels{n}, lag))
wrapthisfigure(thisfig, sprintf('PAI-%s-lag%d-%s-WITHTITLE', ncode{n}, lag, modeltype), wrap);
end
end
close all
end
end
%% finish loop
close all % dockAllFigures
finishwrap
end
%% finish script
finishscript