post_normal {bvartools} | R Documentation |
Produces a draw of coefficients from a normal posterior density.
post_normal(y, x, sigma_i, a_prior, v_i_prior)
y |
a K \times T matrix of endogenous variables. |
x |
an M \times T matrix of explanatory variables. |
sigma_i |
the inverse of the K \times K variance-covariance matrix. |
a_prior |
a KM \times 1 numeric vector of prior means. |
v_i_prior |
the inverse of the KM \times KM prior covariance matrix. |
The function produces a vectorised posterior draw a of the K \times M coefficient matrix A for the model
y_{t} = A x_{t} + u_{t},
where y_{t} is a K-dimensional vector of endogenous variables, x_{t} is an M-dimensional vector of explanatory variabes and the error term is u_t \sim Σ.
For a given prior mean vector \underline{a} and prior covariance matrix \underline{V} the posterior covariance matrix is obtained by
\overline{V} = ≤ft[ \underline{V}^{-1} + ≤ft(X X^{\prime} \otimes Σ^{-1} \right) \right]^{-1}
and the posterior mean by
\overline{a} = \overline{V} ≤ft[ \underline{V}^{-1} \underline{a} + vec(Σ^{-1} Y X^{\prime}) \right],
where Y is a K \times T matrix of the endogenous variables and X is an M \times T matrix of the explanatory variables.
A vector.
Lütkepohl, H. (2007). New introduction to multiple time series analysis (2nd ed.). Berlin: Springer.
# Prepare data data("e1") data <- diff(log(e1)) temp <- gen_var(data, p = 2, deterministic = "const") y <- temp$Y x <- temp$Z k <- nrow(y) t <- ncol(y) m <- k * nrow(x) # Priors a_mu_prior <- matrix(0, m) a_v_i_prior <- diag(0.1, m) # Initial value of inverse Sigma sigma_i <- solve(tcrossprod(y) / t) # Draw parameters a <- post_normal(y = y, x = x, sigma_i = sigma_i, a_prior = a_mu_prior, v_i_prior = a_v_i_prior)