#' Coefficient matrices of the MA represention
#'
#' Returns the estimated coefficient matrices of the moving average
#' representation of a stable VAR(p), of an SVAR as an array or a converted
#' VECM to VAR.
#' This is a modification of vars::Phi() for the class "varshrinkest".
#'
#' @param x An object of class 'varshrinkest',
#' generated by \code{VARshrink()}.
#' @param nstep An integer specifying the number of moving error
#' coefficient matrices to be calculated.
#' @param ... Currently not used.
#' @seealso \code{\link[vars]{Phi}}
#' @export
Phi.varshrinkest <-
function (x, nstep = 10, ...) {
if (!(inherits(x, "varest"))) {
stop("\nPlease provide an object inheriting class 'varest'.\n")
}
nstep <- abs(as.integer(nstep))
K <- x$K
p <- x$p
A <- as.array(Acoef_sh(x))
if (nstep >= p) {
As <- array(0, dim = c(K, K, nstep + 1))
for (i in (p + 1):(nstep + 1)) {
As[, , i] <- matrix(0, nrow = K, ncol = K)
}
}
else {
As <- array(0, dim = c(K, K, p))
}
for (i in 1:p) {
As[, , i] <- A[[i]]
}
Phi <- array(0, dim = c(K, K, nstep + 1))
Phi[, , 1] <- diag(K)
Phi[, , 2] <- Phi[, , 1] %*% As[, , 1]
if (nstep > 1) {
for (i in 3:(nstep + 1)) {
tmp1 <- Phi[, , 1] %*% As[, , i - 1]
tmp2 <- matrix(0, nrow = K, ncol = K)
idx <- (i - 2):1
for (j in 1:(i - 2)) {
tmp2 <- tmp2 + Phi[, , j + 1] %*% As[, , idx[j]]
}
Phi[, , i] <- tmp1 + tmp2
}
}
return(Phi)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.