-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.qmd
1196 lines (826 loc) · 33.1 KB
/
index.qmd
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Bayesian Vector Autoregressions"
author: "by Tomasz Woźniak"
email: "[email protected]"
title-slide-attributes:
data-background-color: "#F500BD"
number-sections: false
format:
revealjs:
theme: [simple, theme.scss]
slide-number: c
transition: concave
smaller: true
multiplex: true
execute:
echo: true
---
## {background-color="#F500BD"}
$$ $$
### Vector Autoregressions
### Three Useful Distributions
### Bayesian Estimation
### Minnesota and Dummy Observations Prior
### Bayesian Estimation for Hierarchical Prior
### Bayesian Forecasting using VARs
### US Data Analysis Using R Package bsvarSIGNs
## {background-color="#001D31"}
![](bsvarSIGNs.png){.absolute top=30 right=275 width="500"}
## Materials {background-color="#F500BD"}
$$ $$
### Lecture Slides [as a Website](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
### A Dedicated Reading [Woźniak (2016, AERev)]( https://doi.org/10.1111/1467-8462.12179)
### **Quarto** [document template](https://github.com/bsvars/2024-10-be24-bsvarSIGNs/blob/main/be23-AUdata.qmd) for your own Australian data forecasting
### GitHub [repo](https://github.com/bsvars/2024-10-be24-bsvarSIGNs) to reproduce the slides and results
### A [Kahoot!](https://kahoot.it/) Quiz
### Tasks
## Vector Autoregressions {background-color="#F500BD"}
## Vector Autoregressions
- go-to models for forecasting
::: incremental
- simple: *linear and Gaussian*
- extendible: *featuring many variations in specification*
- non-normality
- heteroskedasticity
- time-varying parameters
- Bayesian
- interpretable
- Granger causality
- spillovers
- networks
- structural
- Proposed by [Sims (1980)](https://doi.org/10.2307/1912017)
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## VAR(p) Model
### Model equations.
\begin{align*}
y_t &= \mathbf{A}_1 y_{t-1} + \dots + \mathbf{A}_p y_{t-p} + \boldsymbol\mu_0 + \epsilon_t\\
\epsilon_t|Y_{t-1} &\sim iidN\left(\mathbf{0}_N,\mathbf\Sigma\right)
\end{align*} for $t=1,\dots,T$
::: fragment
### Notation.
- $y_t$ is an $N\times 1$ vector of observations at time $t$
- $\mathbf{A}_i$ - $N\times N$ matrix of autoregressive slope parameters
- $\boldsymbol\mu_0$ - $N\times 1$ vector of constant terms
- $\epsilon_t$ - $N\times 1$ vector of error terms - a multivariate white noise process
- $Y_{t-1}$ - information set collecting observations on} $y$ up to time $t-1$
- $\mathbf\Sigma$ - $N\times N$ covariance matrix of the error term
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## A Bivariate VAR(2) Model
Let the number of variable $N=2$ and the lag order $p=2$.
Then, the model equation is:
```{=tex}
\begin{align*}
\begin{bmatrix} y_{1.t} \\ y_{2.t} \end{bmatrix}
&= \begin{bmatrix} \mathbf{A}_{1.11} & \mathbf{A}_{1.12} \\ \mathbf{A}_{1.21} & \mathbf{A}_{1.22} \end{bmatrix} \begin{bmatrix} y_{1.t-1} \\ y_{2.t-1} \end{bmatrix}
+ \begin{bmatrix} \mathbf{A}_{2.11} & \mathbf{A}_{2.12} \\ \mathbf{A}_{2.21} & \mathbf{A}_{2.22} \end{bmatrix} \begin{bmatrix} y_{1.t-2} \\ y_{2.t-2} \end{bmatrix} + \begin{bmatrix} \boldsymbol\mu_{0.1} \\ \boldsymbol\mu_{0.2} \end{bmatrix} + \begin{bmatrix} \epsilon_{1.t} \\ \epsilon_{2.t} \end{bmatrix}\\[2ex]
\begin{bmatrix} \epsilon_{1.t} \\ \epsilon_{2.t} \end{bmatrix} &\Big|Y_{t-1} \sim iid N_2\left( \begin{bmatrix} 0\\ 0\end{bmatrix}, \begin{bmatrix}\boldsymbol\sigma_1^2 & \boldsymbol\sigma_{12} \\ \boldsymbol\sigma_{12} & \boldsymbol\sigma_2^2\end{bmatrix} \right)
\end{align*}
```
. . .
### Task:
Perform the matrix multiplications and write out the equations for $y_{1.t}$.
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Three Useful Distributions {background-color="#F500BD"}
## Matrix-Variate Normal Distribution
A $K\times N$ matrix $\mathbf{A}$ is said to follow a *matrix-variate normal* distribution: $$ \mathbf{A} \sim MN_{K\times N}\left( M, Q, P \right), $$ where
- $M$ - a $K\times N$ matrix of the mean
- $Q$ - a $N\times N$ row-specific covariance matrix
- $P$ - a $K\times K$ column-specific covariance matrix
if $\text{vec}(\mathbf{A})$ is multivariate normal: $$ \text{vec}(\mathbf{A}) \sim N_{KN}\left( \text{vec}(M), Q\otimes P \right) $$
### Density function.
```{=tex}
\begin{align*}
MN_{K\times N}\left( M, Q, P \right) &\propto \exp\left\{ -\frac{1}{2}\text{tr}\left[ Q^{-1}(\mathbf{A}-M)'P^{-1}(\mathbf{A}-M) \right] \right\}
\end{align*}
```
- $\text{tr}()$ is a trace of a matrix - a sum of diagonal elements
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Inverse Wishart Distribution
An $N\times N$ square symmetric and positive definite matrix $\mathbf\Sigma$ follows an *inverse Wishart* distribution: $$ \mathbf\Sigma \sim IW_{N}\left( S, \nu \right) $$ where
- $S$ is $N\times N$ positive definite symmetric matrix called the scale matrix
- $\nu \geq N$ denotes degrees of freedom, if its density is given by:
### Density function.
```{=tex}
\begin{align*}
IW_{N}\left( S, \nu \right) \propto \text{det}(\mathbf\Sigma)^{-\frac{\nu+N+1}{2}}\exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf\Sigma^{-1} S \right] \right\}
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Normal-Inverse Wishart Distribution
```{=tex}
\begin{align*}
\mathbf{A}|\mathbf\Sigma &\sim MN_{K\times N}\left( M, \mathbf\Sigma, P \right)\\
\mathbf\Sigma &\sim IW_{N}\left( S, \nu \right)
\end{align*}
```
then the joint distribution of $(\mathbf{A},\mathbf\Sigma)$ is *normal-inverse Wishart* $$
p(\mathbf{A},\mathbf\Sigma) = NIW_{K\times N}\left( M,P,S,\nu\right)
$$
### Density function.
```{=tex}
\begin{align*}
NIW_{K\times N}\left( M,P,S,\nu\right) \propto &\text{det}(\mathbf{\Sigma})^{-(\nu+N+K+1)/2}\exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf{\Sigma}^{-1} S \right] \right\}\\
&\times\exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf{\Sigma}^{-1} (\mathbf{A}-M)'P^{-1}(\mathbf{A}-M) \right] \right\}
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Example: Error Term Distribution
The model assumptions state: \begin{align*}
\epsilon_t|Y_{t-1} &\sim iidN_N\left(\mathbf{0}_N,\mathbf\Sigma\right)
\end{align*}
Collect error term vectors in a $T\times N$ matrix: $$\underset{(T\times N)}{E}= \begin{bmatrix}\epsilon_1 & \epsilon_2 & \dots & \epsilon_{T}\end{bmatrix}'$$
Error term matrix is matrix-variate distributed: \begin{align*}
E|X &\sim MN_{T\times N}\left(\mathbf{0}_{T\times N},\mathbf\Sigma, I_T\right)
\end{align*}
::: {.fragment .fade-in}
### Tasks: what is
- the covariance of $\text{vec}(E)$
- the distribution of the first equation error terms $\begin{bmatrix}\epsilon_{1.1} &\dots&\epsilon_{1.T}\end{bmatrix}'$
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Example: Univariate *Inverse Wishart* Distribution
The *inverse Wishart* density function is proportional to: \begin{align*}
\text{det}(\mathbf\Sigma)^{-\frac{\nu+N+1}{2}}\exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf\Sigma^{-1} S \right] \right\}
\end{align*}
Consider a case where:
- $N=1$
- the matrix $\mathbf\Sigma$ is replaced by a scalar $\boldsymbol\sigma^2$
::: {.fragment .fade-in}
### Task:
- write out the kernel of the density function for $\boldsymbol\sigma^2$
- the kernel of what density it represents?
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Bayesian Estimation {background-color="#F500BD"}
## The model in Matrix Notation
### VAR(p) model.
```{=tex}
\begin{align*}
y_t &= \mathbf{A}_1 y_{t-1} + \dots + \mathbf{A}_p y_{t-p} + \boldsymbol\mu_0 + \epsilon_t\\
\epsilon_t|Y_{t-1} &\sim iidN_N\left(\mathbf{0}_N,\mathbf\Sigma\right)
\end{align*}
```
### Matrix notation.
```{=tex}
\begin{align*}
Y &= X\mathbf{A} + E\\
E|X &\sim MN_{T\times N}\left(\mathbf{0}_{T\times N},\mathbf\Sigma, I_T\right)
\end{align*}
```
::: {.fragment .fade-out}
$$
\underset{(K\times N)}{\mathbf{A}}=\begin{bmatrix} \mathbf{A}_1'\\ \vdots \\ \mathbf{A}_p' \\ \boldsymbol\mu_0' \end{bmatrix} \quad
\underset{(T\times N)}{Y}= \begin{bmatrix}y_1' \\ y_2'\\ \vdots \\ y_T'\end{bmatrix} \quad
\underset{(K\times1)}{x_t}=\begin{bmatrix} y_{t-1}\\ \vdots \\ y_{t-p}\\ 1 \end{bmatrix}\quad
\underset{(T\times K)}{X}= \begin{bmatrix}x_1' \\ x_2' \\ \vdots \\ x_{T}'\end{bmatrix} \quad
\underset{(T\times N)}{E}= \begin{bmatrix}\epsilon_1' \\ \epsilon_2' \\ \vdots \\ \epsilon_{T}'\end{bmatrix}
$$ where $K=pN+1$
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## The model as Predictive Density
### VAR model.
```{=tex}
\begin{align*}
Y &= X\mathbf{A} +E\\
E|X &\sim MN_{T\times N}\left(\mathbf{0}_{T\times N},\mathbf\Sigma, I_T\right)
\end{align*}
```
### Predictive density.
```{=tex}
\begin{align*}
Y|X,\mathbf{A}, \mathbf{\Sigma} &\sim MN_{T\times N}\left(X\mathbf{A},\mathbf{\Sigma},I_T\right)
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Likelihood Function
### Predictive density.
```{=tex}
\begin{align*}
Y|X,\mathbf{A}, \mathbf{\Sigma} &\sim MN_{T\times N}\left(X\mathbf{A},\mathbf{\Sigma},I_T\right)
\end{align*}
```
### Likelihood function.
```{=tex}
\begin{align*}
L\left(\mathbf{A},\mathbf{\Sigma}|Y,X\right)&\propto\text{det}(\mathbf{\Sigma})^{-\frac{T}{2}}\exp\left\{-\frac{1}{2}\text{tr}\left[\mathbf{\Sigma}^{-1}(Y-X\mathbf{A})'(Y-X\mathbf{A})\right]\right\}
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Likelihood Function as NIW
Define the MLE: $\widehat{A}=(X'X)^{-1}X'Y$
Perform simple transformation of the likelihood
```{=tex}
\begin{align*}
L\left(\mathbf{A},\mathbf{\Sigma}|Y,X\right)&\propto\text{det}(\mathbf{\Sigma})^{-\frac{T}{2}}\exp\left\{-\frac{1}{2}\text{tr}\left[\mathbf{\Sigma}^{-1}(Y-X\mathbf{A})'(Y-X\mathbf{A})\right]\right\}\\
&=\text{det}(\mathbf{\Sigma})^{-\frac{T}{2}}\\
&\quad\times\exp\left\{ -\frac{1}{2}\text{tr}\left[\mathbf{\Sigma}^{-1}(\mathbf{A}-\widehat{A})'X'X(\mathbf{A}-\widehat{A}) \right] \right\}\\
&\quad\times \exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf{\Sigma}^{-1}(Y-X\widehat{A})'(Y-X\widehat{A}) \right] \right\}
\end{align*}
```
Under the likelihood, $(\mathbf{A},\mathbf{\Sigma})$ are *normal-inverse Wishart* distributed:
```{=tex}
\begin{align*}
L\left( \mathbf{A},\mathbf{\Sigma}|Y,X \right) &= NIW_{K\times N}\left(\widehat{A},(X'X)^{-1},(Y-X\widehat{A})'(Y-X\widehat{A}), T-N-K-1 \right)
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Prior Distribution
### Construction.
A natural-conjugate prior leads to joint posterior distribution for $(\mathbf{A},\mathbf{\Sigma})$ of the same form \begin{align*}
p\left( \mathbf{A}, \mathbf{\Sigma} \right) &= p\left( \mathbf{A}| \mathbf{\Sigma} \right)p\left( \mathbf{\Sigma} \right)\\
\mathbf{A}|\mathbf{\Sigma} &\sim MN_{K\times N}\left( \underline{A},\mathbf{\Sigma},\underline{V} \right)\\
\mathbf{\Sigma} &\sim IW_N\left( \underline{S}, \underline{\nu} \right)
\end{align*}
### Kernel.
```{=tex}
\begin{align*}
p\left( \mathbf{A},\mathbf{\Sigma} \right)
&\propto \text{det}(\mathbf{\Sigma})^{-\frac{N+K+\underline{\nu}+1}{2}}\\
&\quad\times\exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf{\Sigma}^{-1}(\mathbf{A}-\underline{A})'\underline{V}^{-1}(\mathbf{A}-\underline{A}) \right] \right\}\\
&\quad\times \exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf{\Sigma}^{-1}\underline{S} \right] \right\}
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Posterior Distribution
### Bayes Rule.
```{=tex}
\begin{align*}
p\left( \mathbf{A}, \mathbf{\Sigma}|Y,X \right) &\propto L(\mathbf{A},\mathbf{\Sigma}|Y,X)p\left( \mathbf{A}, \mathbf{\Sigma} \right)\\
&= L(\mathbf{A},\mathbf{\Sigma}|Y,X)p\left( \mathbf{A}| \mathbf{\Sigma} \right)p\left( \mathbf{\Sigma} \right)
\end{align*}
```
### Kernel.
```{=tex}
\begin{align*}
p\left( \mathbf{A},\mathbf{\Sigma} |Y,X\right)
&\propto \text{det}(\mathbf{\Sigma})^{-\frac{T}{2}}\exp\left\{-\frac{1}{2}\text{tr}\left[\mathbf{\Sigma}^{-1}(Y-X\mathbf{A})'(Y-X\mathbf{A})\right]\right\}\\
& \quad\times\text{det}(\mathbf{\Sigma})^{-\frac{N+K+\underline{\nu}+1}{2}}\exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf{\Sigma}^{-1}\underline{S} \right] \right\}\\
&\quad\times\exp\left\{ -\frac{1}{2}\text{tr}\left[ \mathbf{\Sigma}^{-1}(\mathbf{A}-\underline{A})'\underline{V}^{-1}(\mathbf{A}-\underline{A}) \right] \right\}
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Joint Posterior Distribution
### Conditional and marginal.
```{=tex}
\begin{align*}
p\left( \mathbf{A}, \mathbf{\Sigma}|Y,X \right) &= p(\mathbf{A}|Y,X,\mathbf{\Sigma})p\left( \mathbf{\Sigma}|Y,X \right)\\[2ex]
p(\mathbf{A}|Y,X,\mathbf{\Sigma}) &= MN_{K\times N}\left( \overline{A},\mathbf{\Sigma},\overline{V} \right)\\
p(\mathbf{\Sigma}|Y,X) &= IW_N\left( \overline{S}, \overline{\nu} \right)
\end{align*}
```
### Posterior parameters.
```{=tex}
\begin{align*}
\overline{V}&= \left( X'X + \underline{V}^{-1}\right)^{-1} \\
\overline{A}&= \overline{V}\left( X'Y + \underline{V}^{-1}\underline{A} \right)\\
\overline{\nu}&= T+\underline{\nu}\\
\overline{S}&= \underline{S}+Y'Y + \underline{A}'\underline{V}^{-1}\underline{A} - \overline{A}'\overline{V}^{-1}\overline{A}
\end{align*}
```
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Joint Posterior Distribution
### Task.
- Derive the full conditional posterior distribution of $\mathbf{A}$ given $\mathbf{\Sigma}$ and data $Y$ and $X$, denoted by $p(\mathbf{A}|Y,X,\mathbf{\Sigma})$
$$ $$
Hint: Proceed by:
- writing out the kernel of this distribution as a product of the likelihood and the prior,
- collecting all the terms within the exponential function and under the trace operator,
- completing the squares,
- applying the conditioning whenever convenient.
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Posterior Mean of $\mathbf{A}$
Posterior mean of matrix $\mathbf{A}$ is: \begin{align*}
\overline{A} &= \overline{V}\left( X'Y + \underline{V}^{-1}\underline{A} \right)\\[2ex]
&= \overline{V}\left( X'X\widehat{A} + \underline{V}^{-1}\underline{A} \right)\\[2ex]
&= \overline{V} X'X\widehat{A} + \overline{V}\underline{V}^{-1}\underline{A}
\end{align*} <font color="F500BD">a linear combination</font> of the MLE $\widehat{A}$ and the prior mean $\underline{A}$
Note that: $$
\overline{V} X'X + \overline{V}\underline{V}^{-1} = \overline{V} ( X'X + \underline{V}^{-1}) = I_K
$$
[Play with the posterior in an interactive graph](https://rpsychologist.com/d3/bayes/){preview-link="true"}
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Marginal Data Density
According to *Bayes Rule*, the kernel of the posterior is normalised by the *Marginal Data Density* $p(data)$:
$$
p\left( \mathbf{A}, \mathbf{\Sigma}| data \right) = \frac{L(\mathbf{A},\mathbf{\Sigma}| data)p\left( \mathbf{A}, \mathbf{\Sigma} \right)}{p(data)}
$$
For *Bayesian VARs* the posterior is known $$
p\left( \mathbf{A}, \mathbf{\Sigma}| data \right) = MNIW\left(\overline{A},\overline{V}, \overline{S}, \overline{\nu} \right)
$$
and so is the analytical formula for the *MDD*: $$p(data)$$
This can be used to our advantage!
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Minnesota and Dummy Observations Prior {background-color="#F500BD"}
## Minnesota Prior
[Sims, Litterman, Doan (1984)](https://doi.org/10.1080/07474938408800053) proposed an interpretable way of setting the hyper-parameters on the NIW prior $\underline{A}$, $\underline{V}$, $\underline{S}$, and $\underline{\nu}$ for macroeconomic data.
. . .
$$ $$ The prior reflects the following stylised facts about macro time series:
- the data are unit-root non-stationary
- the effect of more lagged variables should be smaller and smaller
- the effect of other variables lags should be less than that of own lags
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Minnesota Prior
### Inverse-Wishart prior.
```{=tex}
\begin{align*}
\mathbf{\Sigma} &\sim IW_N\left( \underline{S}, \underline{\nu} \right)
\end{align*}
```
Set
```{=tex}
\begin{align*}
\underline{S} &= \begin{bmatrix}
\psi_1 &0 &\dots & 0 \\
0 & \psi_2 &\dots & 0\\
\vdots &\vdots&\ddots& \vdots\\
0&0&\dots&\psi_N
\end{bmatrix}\\[2ex]
\underline{\nu}&= N+2
\end{align*}
```
### Hyper-parameters.
$\psi =(\psi_1, \dots, \psi_N)$ have to be chosen (or estimated)
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Minnesota Prior
### Matrix-Variate Normal prior.
```{=tex}
\begin{align*}
\mathbf{A}|\mathbf{\Sigma} &\sim MN_{K\times N}\left( \underline{A},\mathbf{\Sigma},\underline{V} \right)
\end{align*}
```
For $\quad l = 1+\text{floor}((i-1)/N) \quad\text{and }\quad k = i - (l-1)N$, set:
\begin{align*}
\underline{A} &= \begin{bmatrix} I_N \\ \mathbf{0}_{((p-1)N +1)\times N}\end{bmatrix}&
\underline{V}_{ij} &= \left\{\begin{array} (\lambda ^ 2 / (\psi_k l^2) &\text{ for }i=j,\text{ and } i\neq pN+1 \\
\lambda^2 &\text{ for }i=j,\text{ and } i= pN+1 \\
0&\text{ for } i\neq j
\end{array}\right.
\end{align*}
### Hyper-parameters.
$\lambda^2$ has to be chosen (or estimated)
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Minnesota Prior
### Task.
Consider a simple case of a model for $N=2$ observations and with $p=1$ lag.
- write out the $3\times2$ matrix $\underline{A}$ and the $3\times3$ matrix $\underline{V}$ for the Minnesota prior determining every of its elements.
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Dummy Observations Prior
### Idea.
1. Generate artificial data matrices with $T_d$ rows $Y^*$ and $X^*$
2. Append them to the original data matrices $Y$ and $X$ respectively.
::: fragment
### Implied prior distribution.
Use Bayes Rule to derive the joint prior of $(\mathbf{A},\mathbf\Sigma)$ given $Y^*$ and $X^*$.
It is given by the MNIW distribution:
\begin{align*}
p\left( \mathbf{A}, \mathbf{\Sigma}|Y^*,X^* \right) &= MNIV_{K\times N}\left( \underline{A}^*,\underline{V}^*, \underline{S}^*, \underline{\nu}^* \right)
\end{align*} \begin{align*}
\underline{V}^*&= \left( X^{*\prime}X^* + \underline{V}^{-1}\right)^{-1} & \underline{A}^*&= \underline{V}^*\left( X^{*\prime}Y^* + \underline{V}^{-1}\underline{A} \right)\\
\underline{\nu}^*&= T_d+\underline{\nu} & \underline{S}^*&= \underline{S}+Y^{*\prime}Y^* + \underline{A}'\underline{V}^{-1}\underline{A} - \underline{A}^{*\prime}\underline{V}^{*-1}\underline{A}^*
\end{align*}
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Dummy Observations Prior
Let a $p\times N$ matrix $Y_0$ denote the initial observations, that is, the first $p$ observations of the available time series.
Let an $N$-vector $\bar{Y}_0$ denote its columns' means.
::: fragment
### Sum-of-coefficients prior.
Generate additional $N$ rows by $$
Y^+ = \text{diag}\left(\frac{\bar{Y}_0}{\mu}\right) \quad\text{ and }\quad X^+ = \begin{bmatrix}Y^+ & \dots & Y^+ & \mathbf{0}_N \end{bmatrix}
$$
- $\mu$ is a hyper-parameter to be chosen (or estimated)
- if $\mu \rightarrow 0$ the prior implies the presence of a unit root in each equation and rules out cointegration
- if $\mu \rightarrow\infty$ the prior becomes uninformative
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Dummy Observations Prior
### Dummy-initial-observation prior.
Generate an additional row by $$
Y^{++} = \frac{\bar{Y}_0'}{\delta} \quad\text{ and }\quad X^{++} = \begin{bmatrix} Y^{++} & \dots & Y^{++} & \frac{1}{\delta} \end{bmatrix}
$$
- hyper-parameter $\delta$ is to be chosen (or estimated)
- if $\delta \rightarrow 0$ all the variables of the VAR are forced to be at their unconditional mean, or the system is characterized by the presence of an unspecified number of unit roots without drift (cointegration)
- if $\delta \rightarrow\infty$ the prior becomes uninformative
::: fragment
### Combining dummy observations.
$$
Y^* = \begin{bmatrix}Y^+ \\ Y^{++} \end{bmatrix}\quad\text{ and }\quad
X^* = \begin{bmatrix}X^+ \\ X^{++} \end{bmatrix}
$$
:::
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Dummy Observations Prior
### Task.
Suppose that:
- $\bar{Y}_0 = \begin{bmatrix}1&2\end{bmatrix}'$
- $\mu = 0.5$
- $\delta = 3$
- $p = 1$
Write out the matrices $Y^*$ and $X^*$ of dimensions $2\times 3$ and $3\times 3$ respectively.
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Bayesian Estimation for Hierarchical Prior {background-color="#F500BD"}
## Bayesian Estimation for Hierarchical Prior
Hyper-parameters $\psi$, $\lambda$, $\mu$ and $\delta$ can be fixed to values chosen by the econometrician.
### Hierarcical prior.
A better idea is to assume priors for these hyper-parameters and estimate them as in [Giannone, Lenza, Primiceri (2015)](https://doi.org/10.1162/REST_a_00483).
Extend the existing prior to: \begin{align*}
p\left( \mathbf{A}, \mathbf{\Sigma}|Y^*,X^*,\psi,\lambda,\mu,\delta \right) &= MNIV_{K\times N}\left( \underline{A}^*,\underline{V}^*, \underline{S}^*, \underline{\nu}^* \right)
\end{align*} And specify: \begin{align*}
\psi_n &\sim IG\left(0.02^2, 0.02^2\right)\\
\lambda &\sim G\left(0.2,2\right)\\
\mu &\sim G\left(1,2\right)\\
\delta &\sim G\left(1,2\right)
\end{align*}
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Bayesian Estimation for Hierarchical Prior
[Giannone, Lenza, Primiceri (2015)](https://doi.org/10.1162/REST_a_00483) propose the following estimation procedure:
#### Step 1: Estimate $(\psi,\lambda,\mu,\delta)$ using a random-walk Metropolis-Hastings sampler
- Sample these hyper-parameters marginally on $(\mathbf{A},\mathbf\Sigma)$
- extend the conditioning of *Marginal Data Density*: $$ p(data|\psi,\lambda,\mu,\delta)$$
- apply Bayes Rule to obtain the kernel of the posterior:
$$ p(\psi,\lambda,\mu,\delta|data) \propto p(\psi,\lambda,\mu,\delta)p(data|\psi,\lambda,\mu,\delta)$$ - Use an $(N+3)$-variate Student-t distribution as the candidate generating density
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Bayesian Estimation for Hierarchical Prior
#### Step 2: For each draw of $(\psi,\lambda,\mu,\delta)$ sample the corresponding draw of $(\mathbf{A},\mathbf{\Sigma})$
Use the MNIW posterior derived for the implied prior:
```{=tex}
\begin{align*}
p\left( \mathbf{A}, \mathbf{\Sigma}|Y,X, Y^*,X^* \right) &= MNIW_{K\times N}\left( \overline{A}^*,\overline{V}^*,\overline{S}^*, \overline{\nu}^* \right)\\[2ex]
\overline{V}^*&= \left( X'X + \underline{V}^{*-1}\right)^{-1} \\
\overline{A}^*&= \overline{V}^*\left( X'Y + \underline{V}^{*-1}\underline{A}^* \right)\\
\overline{\nu}^*&= T+\underline{\nu}^*\\
\overline{S}^*&= \underline{S}^*+Y'Y + \underline{A}^{*\prime}\underline{V}^{*-1}\underline{A}^* - \overline{A}^{*\prime}\overline{V}^{*-1}\overline{A}^*
\end{align*}
```
### R implementation.
Package [**bsvarSIGNs**](https://cran.r-project.org/package=bsvarSIGNs) by [Wang & Woźniak (2024)](https://doi.org/10.32614/CRAN.package.bsvarSIGNs) implements this algorithm.
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
## Bayesian Forecasting using VARs {background-color="#F500BD"}
## The objective of economic forecasting
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
$\left.\right.$
... is to use the available data to provide a statistical characterisation of the unknown future values of quantities of interest.
$\left.\right.$
The full statistical characterisation of the unknown future values of random variables is given by their *predictive density*.
$\left.\right.$
Simplified outcomes in a form of statistics summarising the predictive densities are usually used in decision-making processes.
$\left.\right.$
Summary statistics are also communicated to general audiences.
## One-Period Ahead Predictive Density
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
### VAR(p) model.
\begin{align*}
y_t &= \mathbf{A}_1 y_{t-1} + \dots + \mathbf{A}_p y_{t-p} + \boldsymbol\mu_0 + \epsilon_t\\[2ex]
\epsilon_t|Y_{t-1} &\sim iidN_N\left(\mathbf{0}_N,\mathbf\Sigma\right)\\
&
\end{align*}
### One-Period Ahead Conditional Predictive Density
... is implied by the model formulation:
\begin{align*}
y_{t+h}|Y_{t+h-1},\mathbf{A},\mathbf\Sigma &\sim N_N\left(\mathbf{A}_1 y_{t+h-1} + \dots + \mathbf{A}_p y_{t+h-p} + \boldsymbol\mu_0,\mathbf\Sigma\right)
\end{align*}
## One-Period Ahead Predictive Density
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
$\left.\right.$
Bayesian forecasting takes into account the uncertainty w.r.t. parameter estimation by integrating it out from the predictive density.
\begin{align*}
&\\
p(y_{T+1}|Y,X) &= \int p(y_{T+1}|Y_{T},\mathbf{A},\mathbf\Sigma) p(\mathbf{A},\mathbf\Sigma|Y,X) d(\mathbf{A},\mathbf\Sigma)\\ &
\end{align*}
- $p(y_{T+1}|Y,X)$ - predictive density
- $p(y_{T+1}|Y_{t},\mathbf{A},\mathbf\Sigma)$ - one-period-ahead conditional predictive density
- $p(\mathbf{A},\mathbf\Sigma|Y,X)$ - marginal posterior distribution
## Sampling from One-Period Ahead Predictive Density
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
$\left.\right.$
#### Step 1: Sample from the posterior
... and obtain $S$ draws $\left\{ \mathbf{A}^{(s)},\mathbf\Sigma^{(s)} \right\}_{s=1}^{S}$
$\left.\right.$
#### Step 2: Sample from the predictive density
In order to obtain draws from $p(y_{T+1}|Y,X)$, for each of the $S$ draws of $(\mathbf{A},\mathbf\Sigma)$ sample the corresponding draw of $y_{T+1}$:
Sample $y_{T+1}^{(s)}$ from
$$
N_N\left(\mathbf{A}_1^{(s)} y_{T} + \dots + \mathbf{A}_p^{(s)} y_{T-p+1} + \boldsymbol\mu_0^{(s)},\mathbf\Sigma^{(s)}\right)
$$
and obtain $\left\{y_{T+1}^{(s)}\right\}_{s=1}^{S}$
## $h$-Period Ahead Predictive Density
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
$\left.\right.$
This procedure can be generalised to any forecasting horizon.
This is an illustration for $h=2$.
\begin{align*}
&\\
p(y_{T+2},y_{T+1}|Y,X)
&= \int p(y_{T+2},y_{T+1}|Y_{T},\mathbf{A},\mathbf\Sigma) p(\mathbf{A},\mathbf\Sigma|Y,X) d(\mathbf{A},\mathbf\Sigma)\\[1ex]
&= \int p(y_{T+2}|y_{T+1},Y_{T},\mathbf{A},\mathbf\Sigma)p(y_{T+1}|Y_{T},\mathbf{A},\mathbf\Sigma) p(\mathbf{A},\mathbf\Sigma|Y,X) d(\mathbf{A},\mathbf\Sigma)\\ &
\end{align*}
## $h$-Period Ahead Predictive Density
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
$\left.\right.$
#### Step 1: Sample from the posterior
... and obtain $S$ draws $\left\{ \mathbf{A}^{(s)},\mathbf\Sigma^{(s)} \right\}_{s=1}^{S}$
#### Step 2: Sample from 1-period ahead predictive density
For each of the $S$ draws, sample $y_{T+1}^{(s)}$ from
$$
N_N\left(\mathbf{A}_1^{(s)} y_{T} + \dots + \mathbf{A}_p^{(s)} y_{T-p+1} + \boldsymbol\mu_0^{(s)},\mathbf\Sigma^{(s)}\right)
$$
#### Step 3: Sample from 2-period ahead predictive density
For each of the $S$ draws, sample $y_{T+2}^{(s)}$ from
$$
N_N\left(\mathbf{A}_1^{(s)} y_{T+1}^{(s)} + \mathbf{A}_2 y_{T} + \dots + \mathbf{A}_p^{(s)} y_{T-p+2} + \boldsymbol\mu_0^{(s)},\mathbf\Sigma^{(s)}\right)
$$
and obtain $\left\{y_{T+2}^{(s)},y_{T+1}^{(s)}\right\}_{s=1}^{S}$
## US Data Analysis Using R Package bsvarSIGNs {background-color="#F500BD"}
## Data
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
```{r}
#| label: us-data
#| warning: false
#| fig-align: "center"
#| fig-height: 11
#| output-location: column
#| cache: true
# upload package
library(bsvarSIGNs)
# upload data
data(optimism)
# plot data
plot.ts(
optimism[,c(1,2,5)],
main = "",
col = "#F500BD",
lwd = 4,
cex.axis = 2,
cex.lab = 2
)
```
## Setup and hyper-parameters estimation
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
```{r}
#| label: priors
#| warning: false
#| messages: false
#| cache: true
# set seed
set.seed(123)
# MCMC settings
burn = 1000
S = 10000
# specify the model
spec = specify_bsvarSIGN$new(
optimism[,c(1,2,5)],
p = 4,
)
# estimate all hyper-parameters
spec$prior$estimate_hyper(
S = S + burn,
burn_in = burn,
mu = TRUE,
delta = TRUE,
lambda = TRUE,
psi = TRUE
)
```
## Setup and hyper-parameters estimation
::: footer
[Bayesian VARs](https://bsvars.github.io/2024-10-be24-bsvarSIGNs)
:::
```{r}
#| label: prior_plot
#| warning: false
#| messages: false
#| cache: true
#| fig-align: "center"
#| fig-height: 11
#| output-location: column
# assign hyper-parameter names to estimation output
rownames(spec$prior$hyper) =
c("mu",
"delta",
"lambda",
paste0("psi", 1:3)
)
# trace plot
plot.ts(