Description Usage Arguments Details Value Examples
View source: R/SVAR-2-estimation.R
Estimate structural matrices By
and Be
by least squares or
maximum likelihood.
1 2 3 | ols_cholesky(Y, p)
mle_svar(Y, p, By, Be)
|
Y |
A |
p |
An integer scalar. The lag length of the VAR(p) system. |
By |
A |
Be |
A |
The two matrices By
and Be
refer to the instantaneous effects matrices
in a vector autoregressive system
By * y_t = A_s(L) y_t + Be * e_t.
Thus, By
describes the contemporaneous effects between the elements of y
. Be
describes the contemporaneous impact a structural error vector e_t
has on
y_t
.
ols_cholesky
Apply OLS and a Cholesky decomposition for recovering
Be
from a simple recursive system. As usual, the ordering of the variables
will matter for a standard Cholesky decomposition. The effect matrix By
is
assumed to be an identity matrix.
mle_svar
Estimate By
and Be
by maximising the
concentrated log-likelihood. The reduced-form parameters are first
estimated by OLS while the remaining structural parameters are estimated by
MLE in a second step. The function covers recursive and non-recursive,
exactly identified and over-identified systems. The necessary restrictions
on matrices By
and Be
are imposed by assigning numeric values to the
restricted elements. Unrestricted elements are left to be estimated by
setting them to NA
.
The results may not necessarily be unique. The column sign, for example, could be indeterminate.
ols_cholesky
A (K x K)
numeric lower triangular matrix.
mle_svar
A list with two elements By
and Be
. Both are (K x K)
numeric matrices. The elements which previously held NA
s were
replaced with estimates.
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 | set.seed(8191)
# number of variables, observations and lag length
K <- 3
N <- 1E6
p <- 2
# prepare input
A <- cbind(matrix(0.1, K, K), matrix(-0.05, K, K)); diag(A) <- 0.4
Be <- matrix(0.4, K, K); Be[upper.tri(Be)] <- 0
Y0 <-matrix(0, nrow = K, ncol = p)
W <- matrix(rnorm(N * K), nrow = K, ncol = N)
# draw data and estimate Be
Y <- create_svar_data(A, Be, Y0, W)
Be_hat <- ols_cholesky(Y, p)
Be_hat
set.seed(8191)
K <- 3
N <- 1E6
p <- 2
A <- cbind(matrix(0.1, K, K), matrix(-0.05, K, K)); diag(A) <- 0.4
Be <- matrix(0.4, K, K); Be[upper.tri(Be)] <- 0
Y0 <-matrix(0, nrow = K, ncol = p)
W <- matrix(rnorm(N * K), nrow = K, ncol = N)
Y <- create_svar_data(A, Be, Y0, W)
By_init <- diag(K)
Be_init <- matrix(0, K, K)
Be_init[lower.tri(Be_init, diag = TRUE)] <- NA
mle_svar(Y, p, By_init, Be_init)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.