knitr::opts_chunk$set( comment = "#>", collapse = TRUE, out.width = "70%", fig.align = "center", fig.width = 6, fig.asp = .618 ) orig_opts <- options("digits") options(digits = 3) set.seed(1)
library(bvhar)
We provide functions to generate matrix-variate Normal and inverse-Wishart.
sim_mnormal(num_sim, mu, sig)
: num_sim
of $\mathbf{X}_i \stackrel{iid}{\sim} N(\boldsymbol{\mu}, \Sigma)$.sim_matgaussian(mat_mean, mat_scale_u, mat_scale_v)
: One $X_{m \times n} \sim MN(M_{m \times n}, U_{m \times m}, V_{n \times n})$ which means that $vec(X) \sim N(vec(M), V \otimes U)$.sim_iw(mat_scale, shape)
: One $\Sigma \sim IW(\Psi, \nu)$.sim_mniw(num_sim, mat_mean, mat_scale_u, mat_scale, shape)
: num_sim
of $(X_i, \Sigma_i) \stackrel{iid}{\sim} MNIW(M, U, V, \nu)$.Multivariate Normal generation gives num_sim
x dim matrix.
For example, generating 3 vector from Normal($\boldsymbol{\mu} = \mathbf{0}_2$, $\Sigma = diag(\mathbf{1}_2)$):
sim_mnormal(3, rep(0, 2), diag(2))
The output of sim_matgaussian()
is a matrix.
sim_matgaussian(matrix(1:20, nrow = 4), diag(4), diag(5), FALSE)
When generating IW, violating $\nu > dim - 1$ gives error. But we ignore $\nu > dim + 1$ (condition for mean existence) in this function. Nonetheless, we recommend you to keep $\nu > dim + 1$ condition. As mentioned, it guarantees the existence of the mean.
sim_iw(diag(5), 7)
In case of sim_mniw()
, it returns list with mn
(stacked MN matrices) and iw
(stacked IW matrices).
Each mn
and iw
has draw lists.
sim_mniw(2, matrix(1:20, nrow = 4), diag(4), diag(5), 7, FALSE)
This function has been defined for the next simulation functions.
Consider BVAR Minnesota prior setting,
$$A \sim MN(A_0, \Omega_0, \Sigma_e)$$
$$\Sigma_e \sim IW(S_0, \alpha_0)$$
Each $A_0, \Omega_0, S_0, \alpha_0$ is defined by adding dummy observations
build_xdummy()
build_ydummy()
sigma
: Vector $\sigma_1, \ldots, \sigma_m$
lambda
m
increases, $\lambda$ should be smaller to avoid overfitting (De Mol et al. (2008))delta
: Persistenceeps
: Very small number to make matrix invertiblebvar_lag <- 5 (spec_to_sim <- set_bvar( sigma = c(3.25, 11.1, 2.2, 6.8), # sigma vector lambda = .2, # lambda delta = rep(1, 4), # 4-dim delta vector eps = 1e-04 # very small number ))
sim_mncoef(p, bayes_spec, full = TRUE)
can generate both $A$ and $\Sigma$ matrices.bayes_spec
, only set_bvar()
works.full = FALSE
, $\Sigma$ is not random. It is same as diag(sigma)
from the bayes_spec
.full = TRUE
is the default.(sim_mncoef(bvar_lag, spec_to_sim))
sim_mnvhar_coef(bayes_spec, full = TRUE)
generates BVHAR model setting:
$$\Phi \mid \Sigma_e \sim MN(M_0, \Omega_0, \Sigma_e)$$
$$\Sigma_e \sim IW(\Psi_0, \nu_0)$$
bayes_spec
option wants bvharspec
. Butset_bvhar()
set_weight_bvhar()
full = TRUE
, too.(bvhar_var_spec <- set_bvhar( sigma = c(1.2, 2.3), # sigma vector lambda = .2, # lambda delta = c(.3, 1), # 2-dim delta vector eps = 1e-04 # very small number ))
(sim_mnvhar_coef(bvhar_var_spec))
(bvhar_vhar_spec <- set_weight_bvhar( sigma = c(1.2, 2.3), # sigma vector lambda = .2, # lambda eps = 1e-04, # very small number daily = c(.5, 1), # 2-dim daily weight vector weekly = c(.2, .3), # 2-dim weekly weight vector monthly = c(.1, .1) # 2-dim monthly weight vector ))
(sim_mnvhar_coef(bvhar_vhar_spec))
options(orig_opts)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.