Nothing
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} or \pkg{bsvarSIGNs} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome obtained by running the \code{estimate} function.
#' The interpretation depends on the normalisation of the shocks
#' using function \code{normalise()}. Verify if the default settings are appropriate.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array with attribute PosteriorShocks
#' containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar$new(us_fiscal_lsuw, p = 1)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar$new(p = 1) |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks <- function(posterior) {
UseMethod("compute_structural_shocks", posterior)
}
#' @method compute_structural_shocks PosteriorBSVAR
#'
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} or \pkg{bsvarSIGNs} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome - an object of class
#' \code{PosteriorBSVAR} obtained by running the \code{estimate} function.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array with attribute PosteriorShocks
#' containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar$new(us_fiscal_lsuw, p = 1)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar$new(p = 1) |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks.PosteriorBSVAR <- function(posterior) {
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
Y = posterior$last_draw$data_matrices$Y
X = posterior$last_draw$data_matrices$X
ss = .Call(`_bsvars_bsvars_structural_shocks`, posterior_B, posterior_A, Y, X)
class(ss) = "PosteriorShocks"
S = dim(ss)[3]
dimnames(ss) = list(rownames(Y), colnames(Y), 1:S)
return(ss)
}
#' @method compute_structural_shocks PosteriorBSVAREXH
#'
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome - an object of class
#' \code{PosteriorBSVAREXH} obtained by running the \code{estimate} function.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array with attribute PosteriorShocks
#' containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar_exh$new(us_fiscal_lsuw)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar_exh$new() |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks.PosteriorBSVAREXH <- function(posterior) {
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
Y = posterior$last_draw$data_matrices$Y
X = posterior$last_draw$data_matrices$X
ss = .Call(`_bsvars_bsvars_structural_shocks`, posterior_B, posterior_A, Y, X)
class(ss) = "PosteriorShocks"
S = dim(ss)[3]
dimnames(ss) = list(rownames(Y), colnames(Y), 1:S)
return(ss)
}
#' @method compute_structural_shocks PosteriorBSVARMSH
#'
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} or \pkg{bsvarSIGNs} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome - an object of class
#' \code{PosteriorBSVARMSH} obtained by running the \code{estimate} function.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array with attribute PosteriorShocks
#' containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar_msh$new(us_fiscal_lsuw, p = 1, M = 2)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar_msh$new(p = 1, M = 2) |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks.PosteriorBSVARMSH <- function(posterior) {
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
Y = posterior$last_draw$data_matrices$Y
X = posterior$last_draw$data_matrices$X
ss = .Call(`_bsvars_bsvars_structural_shocks`, posterior_B, posterior_A, Y, X)
class(ss) = "PosteriorShocks"
S = dim(ss)[3]
dimnames(ss) = list(rownames(Y), colnames(Y), 1:S)
return(ss)
}
#' @method compute_structural_shocks PosteriorBSVARHMSH
#'
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} or \pkg{bsvarSIGNs} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome - an object of class
#' \code{PosteriorBSVARHMSH} obtained by running the \code{estimate} function.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array with attribute PosteriorShocks
#' containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar_hmsh$new(us_fiscal_lsuw)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar_hmsh$new() |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks.PosteriorBSVARHMSH <- function(posterior) {
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
Y = posterior$last_draw$data_matrices$Y
X = posterior$last_draw$data_matrices$X
ss = .Call(`_bsvars_bsvars_structural_shocks`, posterior_B, posterior_A, Y, X)
class(ss) = "PosteriorShocks"
S = dim(ss)[3]
dimnames(ss) = list(rownames(Y), colnames(Y), 1:S)
return(ss)
}
#' @method compute_structural_shocks PosteriorBSVARMIX
#'
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} or \pkg{bsvarSIGNs} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome - an object of class
#' \code{PosteriorBSVARMIX} obtained by running the \code{estimate} function.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array with attribute PosteriorShocks
#' containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar_mix$new(us_fiscal_lsuw, p = 1, M = 2)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar_mix$new(p = 1, M = 2) |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks.PosteriorBSVARMIX <- function(posterior) {
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
Y = posterior$last_draw$data_matrices$Y
X = posterior$last_draw$data_matrices$X
ss = .Call(`_bsvars_bsvars_structural_shocks`, posterior_B, posterior_A, Y, X)
class(ss) = "PosteriorShocks"
S = dim(ss)[3]
dimnames(ss) = list(rownames(Y), colnames(Y), 1:S)
return(ss)
}
#' @method compute_structural_shocks PosteriorBSVARSV
#'
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} or \pkg{bsvarSIGNs} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome - an object of class
#' \code{PosteriorBSVARSV} obtained by running the \code{estimate} function.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array with attribute PosteriorShocks
#' containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar_sv$new(us_fiscal_lsuw, p = 1)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar_sv$new(p = 1) |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks.PosteriorBSVARSV <- function(posterior) {
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
Y = posterior$last_draw$data_matrices$Y
X = posterior$last_draw$data_matrices$X
ss = .Call(`_bsvars_bsvars_structural_shocks`, posterior_B, posterior_A, Y, X)
class(ss) = "PosteriorShocks"
S = dim(ss)[3]
dimnames(ss) = list(rownames(Y), colnames(Y), 1:S)
return(ss)
}
#' @method compute_structural_shocks PosteriorBSVART
#'
#' @title Computes posterior draws of structural shocks
#'
#' @description Each of the draws from the posterior estimation of models from
#' packages \pkg{bsvars} or \pkg{bsvarSIGNs} is transformed into
#' a draw from the posterior distribution of the structural shocks.
#'
#' @param posterior posterior estimation outcome - an object of class
#' \code{PosteriorBSVART} obtained by running the \code{estimate} function.
#'
#' @return An object of class PosteriorShocks, that is, an \code{NxTxS} array
#' with attribute PosteriorShocks containing \code{S} draws of the structural shocks.
#'
#' @seealso \code{\link{estimate}}, \code{\link{normalise}}, \code{\link{summary}}
#'
#' @author Tomasz Woźniak \email{wozniak.tom@pm.me}
#'
#' @examples
#' specification = specify_bsvar_t$new(us_fiscal_lsuw, p = 1)
#' burn_in = estimate(specification, 5)
#' posterior = estimate(burn_in, 5)
#'
#' # compute structural shocks
#' shocks = compute_structural_shocks(posterior)
#'
#' # workflow with the pipe |>
#' ############################################################
#' us_fiscal_lsuw |>
#' specify_bsvar_t$new(p = 1) |>
#' estimate(S = 5) |>
#' estimate(S = 5) |>
#' compute_structural_shocks() -> ss
#'
#' @export
compute_structural_shocks.PosteriorBSVART <- function(posterior) {
posterior_B = posterior$posterior$B
posterior_A = posterior$posterior$A
Y = posterior$last_draw$data_matrices$Y
X = posterior$last_draw$data_matrices$X
ss = .Call(`_bsvars_bsvars_structural_shocks`, posterior_B, posterior_A, Y, X)
class(ss) = "PosteriorShocks"
S = dim(ss)[3]
dimnames(ss) = list(rownames(Y), colnames(Y), 1:S)
return(ss)
}
#' @export
print.PosteriorShocks <- function(x, ...) {
cat("Posterior draws of structural shocks\n")
cat("An array of dimensions:", paste(dim(x), collapse = " x "), "\n")
invisible(x)
}
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.