From 91a93afd4fff9a56feefe66b6f74c72515d9d0f2 Mon Sep 17 00:00:00 2001 From: adamwang15 Date: Tue, 16 Jul 2024 20:16:26 +1000 Subject: [PATCH 1/3] more informative name for sign_B #31 --- R/estimate.BSVARSIGN.R | 7 ++-- R/specify_bsvarSIGN.R | 52 ++++++++++++------------- man/specify_bsvarSIGN.Rd | 4 +- man/specify_identification_bsvarSIGN.Rd | 10 ++--- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/R/estimate.BSVARSIGN.R b/R/estimate.BSVARSIGN.R index 1e87078..8cca0fa 100644 --- a/R/estimate.BSVARSIGN.R +++ b/R/estimate.BSVARSIGN.R @@ -111,9 +111,10 @@ estimate.BSVARSIGN = function(specification, S, thin = 1, show_progress = TRUE) sign[is.na(sign)] = 0 # estimation - qqq = .Call(`_bsvarSIGNs_bsvar_sign_cpp`, S, p, Y, X, identification$VB, - sign, identification$sign_narrative, identification$sign_B, Z, - prior, starting_values, show_progress, thin, max_tries) + qqq = .Call(`_bsvarSIGNs_bsvar_sign_cpp`, S, p, Y, X, + identification$VB, sign, identification$sign_narrative, + identification$sign_relation, Z, prior, + starting_values, show_progress, thin, max_tries) specification$starting_values$set_starting_values(qqq$last_draw) output = specify_posterior_bsvarSIGN$new(specification, qqq$posterior) diff --git a/R/specify_bsvarSIGN.R b/R/specify_bsvarSIGN.R index deba0e8..2652dd1 100644 --- a/R/specify_bsvarSIGN.R +++ b/R/specify_bsvarSIGN.R @@ -72,8 +72,8 @@ verify_narrative = function(N, A) { } # verify all restrictions -verify_all = function(N, sign_irf, sign_narrative, sign_B) { - verify_traditional(N, sign_B) +verify_all = function(N, sign_irf, sign_narrative, sign_relation) { + verify_traditional(N, sign_relation) verify_narrative(N, sign_narrative) @@ -422,8 +422,8 @@ specify_identification_bsvarSIGN = R6::R6Class( sign_irf = array(), #' @field sign_narrative a \code{Mx6} matrix of narrative sign restrictions. sign_narrative = matrix(), - #' @field sign_B a \code{NxN} matrix of sign restrictions on contemporaneous relations. - sign_B = matrix(), + #' @field sign_relation a \code{NxN} matrix of sign restrictions on contemporaneous relations. + sign_relation = matrix(), #' @field max_tries a positive integer with the maximum number of iterations #' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions. max_tries = 1, @@ -452,14 +452,14 @@ specify_identification_bsvarSIGN = R6::R6Class( #' Column 6 (horizons_h): an integer in 1:(T-start_t), number horizons of the restriction, #' if start=t and horizons=h the restriction in on periods t to t+h, #' e.g. when h=0 the restriction in only placed on period t. - #' @param sign_B a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the + #' @param sign_relation a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the #' contemporaneous relations \code{B} between reduced-form errors \code{E} and #' structural shocks \code{U}. Recall the structural equation \code{BE=U}, the inverse #' of \code{B} is the contemporaneous impulse response function. #' @param max_tries a positive integer with the maximum number of iterations #' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions. #' @return Identifying restrictions IdentificationBSVARSIGN. - initialize = function(N, sign_irf, sign_narrative, sign_B, max_tries = 1) { + initialize = function(N, sign_irf, sign_narrative, sign_relation, max_tries = 1) { missing_all = TRUE if (missing(sign_irf)) { @@ -472,18 +472,18 @@ specify_identification_bsvarSIGN = R6::R6Class( } else { missing_all = FALSE } - if (missing(sign_B)) { + if (missing(sign_relation)) { if (missing_all) { - sign_B = diag(N) + sign_relation = diag(N) } else { - sign_B = matrix(rep(0, N^2), ncol = N, nrow = N) + sign_relation = matrix(rep(0, N^2), ncol = N, nrow = N) } } if (is.matrix(sign_irf)) { sign_irf = array(sign_irf, dim = c(dim(sign_irf), 1)) } - verify_all(N, sign_irf, sign_narrative, sign_B) + verify_all(N, sign_irf, sign_narrative, sign_relation) B = matrix(FALSE, N, N) B[lower.tri(B, diag = TRUE)] = TRUE @@ -495,7 +495,7 @@ specify_identification_bsvarSIGN = R6::R6Class( self$sign_irf = sign_irf self$sign_narrative = sign_narrative - self$sign_B = sign_B + self$sign_relation = sign_relation self$max_tries = max_tries }, # END initialize @@ -507,7 +507,7 @@ specify_identification_bsvarSIGN = R6::R6Class( VB = as.list(self$VB), sign_irf = as.array(self$sign_irf), sign_narrative = as.matrix(self$sign_narrative), - sign_B = as.matrix(self$sign_B), + sign_relation = as.matrix(self$sign_relation), max_tries = self$max_tries ) }, # END get_identification @@ -536,13 +536,13 @@ specify_identification_bsvarSIGN = R6::R6Class( #' Column 6 (horizons_h): an integer in 1:(T-start_t), number horizons of the restriction, #' if start=t and horizons=h the restriction in on periods t to t+h, #' e.g. when h=0 the restriction in only placed on period t. - #' @param sign_B a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the + #' @param sign_relation a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the #' contemporaneous relations \code{B} between reduced-form errors \code{E} and #' structural shocks \code{U}. Recall the structural equation \code{BE=U}, the inverse #' of \code{B} is the contemporaneous impulse response function. #' @param max_tries a positive integer with the maximum number of iterations #' for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions. - set_identification = function(N, sign_irf, sign_narrative, sign_B) { + set_identification = function(N, sign_irf, sign_narrative, sign_relation) { B = matrix(FALSE, N, N) B[lower.tri(B, diag = TRUE)] = TRUE @@ -562,22 +562,22 @@ specify_identification_bsvarSIGN = R6::R6Class( } else { missing_all = FALSE } - if (missing(sign_B)) { + if (missing(sign_relation)) { if (missing_all) { - sign_B = diag(N) + sign_relation = diag(N) } else { - sign_B = matrix(rep(0, N^2), ncol = N, nrow = N) + sign_relation = matrix(rep(0, N^2), ncol = N, nrow = N) } } if (is.matrix(sign_irf)) { sign_irf = array(sign_irf, dim = c(dim(sign_irf), 1)) } - verify_all(N, sign_irf, sign_narrative, sign_B) + verify_all(N, sign_irf, sign_narrative, sign_relation) self$sign_irf = sign_irf self$sign_narrative = sign_narrative - self$sign_B = sign_B + self$sign_relation = sign_relation } # END set_identification ) # END public ) # END specify_identification_bsvarSIGN @@ -644,7 +644,7 @@ specify_bsvarSIGN = R6::R6Class( #' Column 6 (horizons_h): an integer in 1:(T-start_t), number horizons of the restriction, #' if start=t and horizons=h the restriction in on periods t to t+h, #' e.g. when h=0 the restriction in only placed on period t. - #' @param sign_B a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the + #' @param sign_relation a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the #' contemporaneous relations \code{B} between reduced-form errors \code{E} and #' structural shocks \code{U}. Recall the structural equation \code{BE=U}, the inverse #' of \code{B} is the contemporaneous impulse response function. @@ -660,7 +660,7 @@ specify_bsvarSIGN = R6::R6Class( p = 1L, sign_irf, sign_narrative, - sign_B, + sign_relation, max_tries = 1, exogenous = NULL, stationary = rep(FALSE, ncol(data)) @@ -687,18 +687,18 @@ specify_bsvarSIGN = R6::R6Class( } else { missing_all = FALSE } - if (missing(sign_B)) { + if (missing(sign_relation)) { if (missing_all) { - sign_B = diag(N) + sign_relation = diag(N) } else { - sign_B = matrix(rep(0, N^2), ncol = N, nrow = N) + sign_relation = matrix(rep(0, N^2), ncol = N, nrow = N) } } if (is.matrix(sign_irf)) { sign_irf = array(sign_irf, dim = c(dim(sign_irf), 1)) } - verify_all(N, sign_irf, sign_narrative, sign_B) + verify_all(N, sign_irf, sign_narrative, sign_relation) B = matrix(FALSE, N, N) B[lower.tri(B, diag = TRUE)] = TRUE @@ -707,7 +707,7 @@ specify_bsvarSIGN = R6::R6Class( self$identification = specify_identification_bsvarSIGN$new(N, sign_irf, sign_narrative, - sign_B, + sign_relation, max_tries) self$prior = specify_prior_bsvarSIGN$new(data, p, exogenous, stationary) diff --git a/man/specify_bsvarSIGN.Rd b/man/specify_bsvarSIGN.Rd index a72068a..e65cf7b 100644 --- a/man/specify_bsvarSIGN.Rd +++ b/man/specify_bsvarSIGN.Rd @@ -102,7 +102,7 @@ Create a new specification of the Bayesian Structural VAR model with sign and na p = 1L, sign_irf, sign_narrative, - sign_B, + sign_relation, max_tries = 1, exogenous = NULL, stationary = rep(FALSE, ncol(data)) @@ -139,7 +139,7 @@ Column 6 (horizons_h): an integer in 1:(T-start_t), number horizons of the restr if start=t and horizons=h the restriction in on periods t to t+h, e.g. when h=0 the restriction in only placed on period t.} -\item{\code{sign_B}}{a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the +\item{\code{sign_relation}}{a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the contemporaneous relations \code{B} between reduced-form errors \code{E} and structural shocks \code{U}. Recall the structural equation \code{BE=U}, the inverse of \code{B} is the contemporaneous impulse response function.} diff --git a/man/specify_identification_bsvarSIGN.Rd b/man/specify_identification_bsvarSIGN.Rd index 0bbc9b2..bf845d4 100644 --- a/man/specify_identification_bsvarSIGN.Rd +++ b/man/specify_identification_bsvarSIGN.Rd @@ -23,7 +23,7 @@ specify_identification_bsvarSIGN$new(N = 5, sign_irf = sign_irf) \item{\code{sign_narrative}}{a \code{Mx6} matrix of narrative sign restrictions.} -\item{\code{sign_B}}{a \code{NxN} matrix of sign restrictions on contemporaneous relations.} +\item{\code{sign_relation}}{a \code{NxN} matrix of sign restrictions on contemporaneous relations.} \item{\code{max_tries}}{a positive integer with the maximum number of iterations for finding a rotation matrix \eqn{Q} that would satisfy sign restrictions.} @@ -49,7 +49,7 @@ Create new identifying restrictions IdentificationBSVARSIGN. N, sign_irf, sign_narrative, - sign_B, + sign_relation, max_tries = 1 )}\if{html}{\out{}} } @@ -82,7 +82,7 @@ Column 6 (horizons_h): an integer in 1:(T-start_t), number horizons of the restr if start=t and horizons=h the restriction in on periods t to t+h, e.g. when h=0 the restriction in only placed on period t.} -\item{\code{sign_B}}{a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the +\item{\code{sign_relation}}{a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the contemporaneous relations \code{B} between reduced-form errors \code{E} and structural shocks \code{U}. Recall the structural equation \code{BE=U}, the inverse of \code{B} is the contemporaneous impulse response function.} @@ -116,7 +116,7 @@ Set new starting values StartingValuesBSVARSIGN. N, sign_irf, sign_narrative, - sign_B + sign_relation )}\if{html}{\out{}} } @@ -148,7 +148,7 @@ Column 6 (horizons_h): an integer in 1:(T-start_t), number horizons of the restr if start=t and horizons=h the restriction in on periods t to t+h, e.g. when h=0 the restriction in only placed on period t.} -\item{\code{sign_B}}{a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the +\item{\code{sign_relation}}{a \code{NxN} matrix with entries in (-1 ,0, 1), sign restrictions on the contemporaneous relations \code{B} between reduced-form errors \code{E} and structural shocks \code{U}. Recall the structural equation \code{BE=U}, the inverse of \code{B} is the contemporaneous impulse response function.} From 71e94cd6bdd3d608ecb7cc1a6a554c2e294b8eae Mon Sep 17 00:00:00 2001 From: adamwang15 Date: Tue, 16 Jul 2024 20:24:40 +1000 Subject: [PATCH 2/3] update progress bar #31 --- src/bsvars_sign.cpp | 2 +- src/sample_hyper.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bsvars_sign.cpp b/src/bsvars_sign.cpp index 0af252b..c43cbde 100644 --- a/src/bsvars_sign.cpp +++ b/src/bsvars_sign.cpp @@ -47,7 +47,7 @@ Rcpp::List bsvar_sign_cpp( if (show_progress) { Rcout << "**************************************************|" << endl; Rcout << " bsvarSIGNs: Bayesian Structural VAR with zero, |" << endl; - Rcout << " sign and narrative restriction |" << endl; + Rcout << " sign and narrative restrictions |" << endl; Rcout << "**************************************************|" << endl; // Rcout << " Gibbs sampler for the SVAR model |" << endl; // Rcout << "**************************************************|" << endl; diff --git a/src/sample_hyper.cpp b/src/sample_hyper.cpp index 517f75f..4e5ec8a 100644 --- a/src/sample_hyper.cpp +++ b/src/sample_hyper.cpp @@ -275,6 +275,10 @@ arma::mat sample_hyper( const Rcpp::List& prior ) { + Rcout << "**************************************************|" << endl; + Rcout << " Adaptive Metropolis MCMC: hyper parameters |" << endl; + Rcout << "**************************************************|" << endl; + mat hypers = metropolis( S, start, narrow_hyper(model, init), W, From 91d44a25b3999f5f804f6441a730fa30b5d405ef Mon Sep 17 00:00:00 2001 From: adamwang15 Date: Tue, 16 Jul 2024 20:31:33 +1000 Subject: [PATCH 3/3] rename files --- R/{estimate.BSVARSIGN.R => estimate.R} | 0 R/{specify_bsvarSIGN.R => specify.R} | 0 man/estimate.BSVARSIGN.Rd | 2 +- man/specify_bsvarSIGN.Rd | 2 +- man/specify_identification_bsvarSIGN.Rd | 2 +- man/specify_posterior_bsvarSIGN.Rd | 2 +- man/specify_prior_bsvarSIGN.Rd | 2 +- 7 files changed, 5 insertions(+), 5 deletions(-) rename R/{estimate.BSVARSIGN.R => estimate.R} (100%) rename R/{specify_bsvarSIGN.R => specify.R} (100%) diff --git a/R/estimate.BSVARSIGN.R b/R/estimate.R similarity index 100% rename from R/estimate.BSVARSIGN.R rename to R/estimate.R diff --git a/R/specify_bsvarSIGN.R b/R/specify.R similarity index 100% rename from R/specify_bsvarSIGN.R rename to R/specify.R diff --git a/man/estimate.BSVARSIGN.Rd b/man/estimate.BSVARSIGN.Rd index e487994..604a35e 100644 --- a/man/estimate.BSVARSIGN.Rd +++ b/man/estimate.BSVARSIGN.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/estimate.BSVARSIGN.R +% Please edit documentation in R/estimate.R \name{estimate.BSVARSIGN} \alias{estimate.BSVARSIGN} \title{Bayesian estimation of a Structural Vector Autoregression diff --git a/man/specify_bsvarSIGN.Rd b/man/specify_bsvarSIGN.Rd index e65cf7b..8fd2761 100644 --- a/man/specify_bsvarSIGN.Rd +++ b/man/specify_bsvarSIGN.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/specify_bsvarSIGN.R +% Please edit documentation in R/specify.R \name{specify_bsvarSIGN} \alias{specify_bsvarSIGN} \title{R6 Class representing the specification of the BSVARSIGN model} diff --git a/man/specify_identification_bsvarSIGN.Rd b/man/specify_identification_bsvarSIGN.Rd index bf845d4..e97cbd7 100644 --- a/man/specify_identification_bsvarSIGN.Rd +++ b/man/specify_identification_bsvarSIGN.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/specify_bsvarSIGN.R +% Please edit documentation in R/specify.R \name{specify_identification_bsvarSIGN} \alias{specify_identification_bsvarSIGN} \title{R6 Class Representing IdentificationBSVARSIGN} diff --git a/man/specify_posterior_bsvarSIGN.Rd b/man/specify_posterior_bsvarSIGN.Rd index fafa028..fa37d63 100644 --- a/man/specify_posterior_bsvarSIGN.Rd +++ b/man/specify_posterior_bsvarSIGN.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/specify_bsvarSIGN.R +% Please edit documentation in R/specify.R \name{specify_posterior_bsvarSIGN} \alias{specify_posterior_bsvarSIGN} \title{R6 Class Representing PosteriorBSVARSIGN} diff --git a/man/specify_prior_bsvarSIGN.Rd b/man/specify_prior_bsvarSIGN.Rd index 9b9e437..13b2a3e 100644 --- a/man/specify_prior_bsvarSIGN.Rd +++ b/man/specify_prior_bsvarSIGN.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/specify_bsvarSIGN.R +% Please edit documentation in R/specify.R \name{specify_prior_bsvarSIGN} \alias{specify_prior_bsvarSIGN} \title{R6 Class Representing PriorBSVAR}