-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmr_docs_vars_bvarm.html
332 lines (246 loc) · 11 KB
/
bmr_docs_vars_bvarm.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Bayesian Macroeconometrics in R (BMR)">
<meta name="author" content="Keith O'Hara">
<meta name="keywords" content="Bayesian, Macroeconometrics, BMR, Economics, PhD student, NYU, New York University, Econometrics, R, C++, Cpp, Research" />
<link rel="shortcut icon" type="image/x-icon" href="siteicon.ico">
<title>BMR: bvarm</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/modern-business.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- Additional Settings -->
<link href="css/yuxuan_settings.css" rel="stylesheet">
<!-- Syntax Highlighter -->
<script type="text/javascript" src="js/syntaxhighlighter.js"></script>
<link type="text/css" rel="stylesheet" href="css/swift_theme.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-93902857-1', 'auto');
ga('send', 'pageview');
</script>
<!-- MathJax -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
</script>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script src="js/jquery.js"></script>
<script>
$(function(){
$("#mynavbar").load("navbar.html")
$("#bmrhead").load("bmr_header.html")
$("#myfooter").load("footer.html")
});
</script>
</head>
<style>
pre {
display: inline-block;
}
</style>
<body>
<!-- Navigation -->
<div id="mynavbar"></div>
<!-- Page Content -->
<div class="container">
<!-- Page Heading/Breadcrumbs -->
<div id="bmrhead"></div>
<br>
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-5">
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" href="#collapse1"><h4><strong style="font-size: 120%;">BMR: BVAR with Minnesota Prior</strong></h4></a>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<a href="#definition">Fields and Methods</a> <br>
<a href="#details">Details</a> <br>
<a href="#examples">Examples</a>
</div>
</div>
</div>
</div>
</div>
<!-- -->
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<p>BVAR with Minnesota prior.</p>
<hr style="height:2px;border-width:0;background-color:black">
<h3 style="text-align: left;" id="definition"><strong style="font-size: 100%;">Fields and Methods</strong></h3>
<br>
<p><strong>Instantiation:</strong></p>
<pre class="brush: R;">
# create a new object
bvar_obj <- new(bvarm)
</pre>
<p><strong>Fields:</strong></p>
<ul>
<li><code>cons_term</code> a logical value (TRUE/FALSE) indicating the presence of a constant term (intercept) in the model.</li>
<li><code>p</code> lag order (integer).</li>
<li><code>var_type</code> variance type (1 or 2); see below for more details.</li>
<li><code>decay_type</code> decay type (1 or 2) for the <code>var_type=2</code> case.</li>
<li><code>c_int</code> integer version of <code>cons_term</code>.</li>
<br>
<li><code>n</code> sample length.</li>
<li><code>M</code> number of variables.</li>
<li><code>n_ext_vars</code> number of exogenous variables.</li>
<li><code>K</code> number of right-hand-side terms in each equation.</li>
<br>
<li><code>Y</code> a $(n-p) \times M$ data matrix.</li>
<li><code>X</code> a $(n-p) \times K$ data matrix.</li>
<br>
<li><code>alpha_hat</code> OLS estimate of $\alpha = \text{vec}(\beta)$.</li>
<li><code>Sigma_hat</code> OLS estimate of $\Sigma$.</li>
<br>
<li><code>alpha_pr_mean</code> prior mean of $\alpha = \text{vec}(\beta)$.</li>
<li><code>alpha_pr_var</code> prior covariance matrix of $\alpha = \text{vec}(\beta)$.</li>
<br>
<li><code>alpha_pt_mean</code> posterior mean of $\alpha = \text{vec}(\beta)$.</li>
<li><code>alpha_pt_var</code> posterior covariance matrix of $\alpha = \text{vec}(\beta)$.</li>
<br>
<li><code>beta_draws</code> an array of posterior draws for $\beta$.</li>
</ul>
<hr>
<p><strong>Build:</strong></p>
<pre class="brush: R;">
bvar_obj$build(data_endog,cons_term,p)
bvar_obj$build(data_endog,data_exog,cons_term,p)
</pre>
<ul>
<li><code>data_endog</code> a $n \times M$ matrix of endogenous varibles.</li>
<li><code>data_exog</code> a $n \times q$ matrix of exogenous varibles.</li>
<li><code>cons_term</code> a logical value (TRUE/FALSE) indicating the presence of a constant term (intercept) in the model.</li>
<li><code>p</code> lag order (integer).</li>
</ul>
<p><strong>Prior:</strong></p>
<pre class="brush: R;">
bvar_obj$prior(coef_prior)
bvar_obj$prior(coef_prior,var_type,decay_type,HP_1,HP_2,HP_3,HP_4)
</pre>
<ul>
<li><code>coef_prior</code> a $m \times 1$ vector containing the prior mean for each first own-lag coefficient.</li>
<li><code>var_type</code> variance type (1 or 2); see below for more details.</li>
<li><code>decay_type</code> decay type (1 or 2) for the <code>var_type=2</code> case.</li>
<li><code>HP_1,HP_2,HP_3,HP_4</code> hyperparameters; see below for more details.</li>
</ul>
<p><strong>Gibbs sampling:</strong></p>
<pre class="brush: R;">
bvar_obj$gibbs(n_draws)
</pre>
<ul>
<li><code>n_draws</code> number of posterior draws.</li>
</ul>
<hr style="height:2px;border-width:0;background-color:black">
<h3 style="text-align: left;" id="details"><strong style="font-size: 100%;">Details</strong></h3>
<br>
<p>The model:</p>
$$
y_t = \beta_0 + y_{t-1} \beta_1 + \cdots y_{t-p} \beta_p + e_t, \ \ e_t \stackrel{\text{iid}}{\sim} \mathcal{N} \left( \mathbf{0}, \Sigma \right)
$$
<p>where $y_t$ is a $1 \times M$ vector. We write this in stacked form as:</p>
$$
Y = X \beta + e
$$
<p>The Minnesota prior (also known as Litterman's prior) holds $\Sigma$ fixed to a data-based estimate for posterior sampling of $\beta$, a simplification that yields significant computational speedups compared with the independent Normal-inverse-Wishart model. For references, see Doan, Litterman, and Sims (1983) and Litterman (1986).</p>
<hr>
<p>With the Minnesota prior, $\Sigma$ is a diagonal matrix whose elements are derived from equation-by-equation estimation of AR($p$) models, one for each variable in the VAR system.
That is, for each variable in the VAR model, we estimate the model imposing that all coefficients, except own-lag terms (and a possible constant), are equal to zero. Then:<p>
$$
\Sigma = \begin{bmatrix} \sigma_{1}^2 &0 & 0 & \cdots & 0 \\ 0& \sigma_2^2 & 0 & \cdots & 0 \\ 0& 0 & \sigma_3^2 & \ddots & 0 \\ \vdots & \vdots & \ddots & \ddots & \vdots \\ 0& 0 & 0 & 0 & \sigma_M^2 \end{bmatrix}
$$
<br>
<p>The prior for $\alpha = \text{vec}(\beta)$ is:</p>
$$
p(\alpha) = \mathcal{N}(\bar{\alpha},\Xi_\alpha)
$$
<p>The prior mean of the coefficients, $\bar{\alpha}$, is a $K M \times 1$ vector of zeros, except for elements that relate to the fist-order own-lags terms. The latter values are set by <code>coef_prior</code> the prior function.</p>
<p>Construction of the prior variance matrix for $\beta$ is set in one of two ways.</p>
<ul>
<li>Let $i, j \in \{ 1,\ldots, m\}$. Equations are indexed by $i$, and variables by $j$. We denote lags by $\ell \in \{1, \ldots, p\}$.</li>
<li><code>var_type=1</code> Koop and Korobilis (2010) version of the prior covariance matrix for $\beta$:
\begin{equation*}
\Xi_{\beta_{i,j}} (\ell) =
\begin{cases}
&H_1 / \ell^2 \\
& H_2 \cdot \sigma_{i}^2 / \left( \ell^2 \cdot \sigma_{j}^2 \right) \\
& H_3 \cdot \sigma_{i}^2
\end{cases}
\end{equation*}
which correspond to own lags, cross-variable lags, and exogenous variables (e.g., a constant), respectively.</li>
<li><code>var_type=2</code> Canova (2007) uses a general form for the decay:
\begin{equation*}
\Xi_{\beta_{i,j}} (\ell) =
\begin{cases}
& H_1 / d(\ell) \\
& H_1 \cdot H_2 \cdot \sigma_{j}^2 / \left( d(\ell) \cdot \sigma_{i}^2 \right) \\
& H_1 \cdot H_3
\end{cases}
\end{equation*}
which, again, correspond to own lags, cross-variable lags, and exogenous variables, respectively. $d(\ell)$ is the <em>decay</em> function.
<br><br>
In the Koop and Korobilis (2010) case, $d(\ell) = \ell^2$. Note also that, for cross-equation coefficients, the ratio of the variance of each equation has been inverted.
<br><br>
The user can choose between two functional forms for $d(\ell)$, both index by a hyperparameter $H_4 > 0$:
<ul>
<li><code>decay_type=1</code> harmonic decay, where $d (\ell) = \ell^{H_4}$;</li>
<li><code>decay_type=2</code> geometric decay, where $d (\ell) = H_4^{-\ell + 1}$.</li>
</ul>
When $H_4 = 1$, we have linear decay.
</ul>
<p>$\Xi_{\beta}$ is then vectorised and becomes the main diagonal of $\Xi_\alpha$, with all off-diagonal elemnts of $\Xi_\alpha$ set to zero.</p>
<p>With $\Sigma$ fixed, the posterior distribution of $\alpha = \text{vec}(\beta)$ is given by
\begin{equation}
p(\alpha | \Sigma,X,Y) = \mathcal{N} \left( \widetilde{\alpha}, \widetilde{\Sigma}_{\alpha} \right),
\end{equation}
where
\begin{align*}
\widetilde{\Sigma}_{\alpha}^{-1} &= \Xi_{\alpha}^{-1} + (\Sigma^{-1} \otimes X^{\top} X) \\
\widetilde{\alpha} &= \widetilde{\Sigma}_{\alpha} \left( \Xi_{\alpha}^{-1} \bar{\alpha} + \text{vec}(X^{\top} Y \Sigma^{-1}) \right)
\end{align*}
</p>
<hr style="height:2px;border-width:0;background-color:black">
<h3 style="text-align: left;" id="examples"><strong style="font-size: 100%;">Example</strong></h3>
<br>
<pre class="brush: ruby;">
rm(list=ls())
library(BMR)
#
data(BMRVARData)
bvar_data <- data.matrix(USMacroData[,2:4])
#
coef_prior <- c(0.9,0.9,0.9)
bvar_obj <- new(bvarm)
#
bvar_obj$build(bvar_data,TRUE,4)
bvar_obj$prior(coef_prior,1,1,0.5,0.5,100.0,1.0)
bvar_obj$gibbs(10000)
IRF(bvar_obj,20,var_names=colnames(USMacroData),save=FALSE)
plot(bvar_obj,var_names=colnames(USMacroData),save=FALSE)
forecast(bvar_obj,shocks=TRUE,var_names=colnames(USMacroData),back_data=10,save=FALSE)
</pre>
<hr>
</div>
</div>
</div>
<div id="myfooter"></div>
<!-- jQuery -->
<!--<script src="js/jquery.js"></script>-->
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>