diff --git a/R/bsvarSIGNs-package.R b/R/bsvarSIGNs-package.R index 375ae82..fa0ec55 100644 --- a/R/bsvarSIGNs-package.R +++ b/R/bsvarSIGNs-package.R @@ -24,9 +24,7 @@ #' #' Antolín-Díaz & Rubio-Ramírez (2018) Narrative Sign Restrictions for SVARs, American Economic Review, 108(10), 2802-29, . #' @examples -#' sign_irf = matrix(NA, 5, 5) -#' sign_irf[2, 1] = 1 -#' sign_irf[1, 1] = 0 +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) #' spec = specify_bsvarSIGN$new(optimism * 100, #' p = 4, #' sign_irf = sign_irf) diff --git a/R/compute.R b/R/compute.R index ea904a5..cea4bf0 100644 --- a/R/compute.R +++ b/R/compute.R @@ -21,12 +21,12 @@ #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' #' # specify the model and set seed #' set.seed(123) -#' sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -#' specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) #' #' # run the burn-in #' posterior = estimate(specification, 10) @@ -37,7 +37,7 @@ #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 20) |> #' compute_structural_shocks() -> ss @@ -81,12 +81,12 @@ compute_structural_shocks.PosteriorBSVARSIGN <- function(posterior) { #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' #' # specify the model and set seed #' set.seed(123) -#' sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -#' specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) #' #' # run the burn-in #' posterior = estimate(specification, 10) @@ -97,7 +97,7 @@ compute_structural_shocks.PosteriorBSVARSIGN <- function(posterior) { #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 20) |> #' compute_fitted_values() -> fitted @@ -151,12 +151,12 @@ compute_fitted_values.PosteriorBSVARSIGN <- function(posterior) { #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' #' # specify the model and set seed #' set.seed(123) -#' sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -#' specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) #' #' # run the burn-in #' posterior = estimate(specification, 10) @@ -167,7 +167,7 @@ compute_fitted_values.PosteriorBSVARSIGN <- function(posterior) { #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 10) |> #' compute_impulse_responses(horizon = 8) -> ir @@ -223,12 +223,12 @@ compute_impulse_responses.PosteriorBSVARSIGN <- function(posterior, horizon, sta #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' #' # specify the model and set seed #' set.seed(123) -#' sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -#' specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) #' #' # run the burn-in #' posterior = estimate(specification, 10) @@ -239,7 +239,7 @@ compute_impulse_responses.PosteriorBSVARSIGN <- function(posterior, horizon, sta #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 10) |> #' compute_historical_decompositions() -> hd @@ -300,12 +300,12 @@ compute_historical_decompositions.PosteriorBSVARSIGN <- function(posterior, show #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' #' # specify the model and set seed #' set.seed(123) -#' sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -#' specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) #' #' # run the burn-in #' posterior = estimate(specification, 10) @@ -316,7 +316,7 @@ compute_historical_decompositions.PosteriorBSVARSIGN <- function(posterior, show #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 10) |> #' compute_variance_decompositions(horizon = 8) -> fevd @@ -365,12 +365,12 @@ compute_variance_decompositions.PosteriorBSVARSIGN <- function(posterior, horizo #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' #' # specify the model and set seed #' set.seed(123) -#' sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -#' specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) #' #' # run the burn-in #' posterior = estimate(specification, 10) @@ -381,7 +381,7 @@ compute_variance_decompositions.PosteriorBSVARSIGN <- function(posterior, horizo #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 10) |> #' compute_conditional_sd() -> csd diff --git a/R/data.R b/R/data.R index 668b382..d72672f 100644 --- a/R/data.R +++ b/R/data.R @@ -1,26 +1,4 @@ -#' @title A 3-variable oil price data, from 1971 to 2016 -#' -#' @description A sample data to identify oil demand and supply shocks. -#' -#' @usage data(oil) -#' -#' @format A matrix and a \code{ts} object with time series of over five hundred observations on 3 variables: -#' \describe{ -#' \item{opg}{monthly growth rate of global oil production} -#' \item{eai}{monthly index of real economic activity} -#' \item{rop}{monthly real oil price} -#' } -#' -#' The series are as described by Antolín-Díaz & Rubio-Ramírez (2018) in section IV-A. -#' -#' @references -#' Antolín-Díaz & Rubio-Ramírez (2018) Narrative Sign Restrictions for SVARs, American Economic Review, 108(10), 2802-29, . -#' -#' @source -#' Replication package, \url{https://www.aeaweb.org/articles?id=10.1257/aer.20161852} -"oil" - #' @title A 5-variable US business cycle data, from 1955 Q1 to 2004 Q4 #' diff --git a/R/estimate.BSVARSIGN.R b/R/estimate.BSVARSIGN.R index 0035070..1e87078 100644 --- a/R/estimate.BSVARSIGN.R +++ b/R/estimate.BSVARSIGN.R @@ -75,20 +75,15 @@ #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' -#' # restrictions as in Antolín-Díaz & Rubio-Ramírez (2018) -#' sign_narrative = matrix(c(2, -1, 3, 2, 236, 0), ncol = 6) -#' sign_irf = array(matrix(c(-1, -1, 1, 1, 1, 1, 1, -1, 1), nrow = 3), -#' dim = c(3, 3, 1)) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) #' #' # specify the model and set seed #' set.seed(123) -#' specification = specify_bsvarSIGN$new(oil, -#' p = 12, -#' sign_irf = sign_irf, -#' sign_narrative = sign_narrative -#' ) +#' specification = specify_bsvarSIGN$new(optimism * 100, +#' p = 12, +#' sign_irf = sign_irf) #' posterior = estimate(specification, S = 10) #' #' @export diff --git a/R/forecast.R b/R/forecast.R index d3ae6c8..d52c13c 100644 --- a/R/forecast.R +++ b/R/forecast.R @@ -33,12 +33,12 @@ #' #' @examples #' # upload data -#' data(oil) +#' data(optimism) #' #' # specify the model and set seed #' set.seed(123) -#' sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -#' specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) #' #' # estimate the model #' posterior = estimate(specification, 20) @@ -49,7 +49,7 @@ #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 20) |> #' forecast(horizon = 4) -> predictive @@ -57,14 +57,15 @@ #' # conditional forecasting 2 quarters ahead conditioning on #' # provided future values for the Gross Domestic Product #' ############################################################ -#' cf = matrix(NA , 2, 3) -#' cf[,3] = tail(oil, 1)[3] # conditional forecasts equal to the last gdp observation -#' predictive = forecast(posterior, 2, conditional_forecast = cf) +#' cf = matrix(NA , 2, 5) +#' # # conditional forecasts equal to the last consumption observation +#' cf[,3] = tail(optimism, 1)[3] +#' predictive = forecast(posterior, 2, conditional_forecast = cf) #' #' # workflow with the pipe |> #' ############################################################ #' set.seed(123) -#' oil |> +#' optimism |> #' specify_bsvarSIGN$new(sign_irf = sign_irf) |> #' estimate(S = 10) |> #' forecast(horizon = 2, conditional_forecast = cf) -> predictive diff --git a/R/specify_bsvarSIGN.R b/R/specify_bsvarSIGN.R index 038f7c0..deba0e8 100644 --- a/R/specify_bsvarSIGN.R +++ b/R/specify_bsvarSIGN.R @@ -128,10 +128,10 @@ igamma_shape = function(mode, variance) { #' The class PriorBSVARSIGN presents a prior specification for the homoskedastic bsvar model. #' #' @examples -#' # a prior for 3-variable example with one lag -#' data(oil) -#' prior = specify_prior_bsvarSIGN$new(oil, p = 1) -#' prior$B # show autoregressive prior mean +#' # a prior for 5-variable example with one lag +#' data(optimism) +#' prior = specify_prior_bsvarSIGN$new(optimism, p = 1) +#' prior$A # show autoregressive prior mean #' #' @export specify_prior_bsvarSIGN = R6::R6Class( @@ -215,9 +215,9 @@ specify_prior_bsvarSIGN = R6::R6Class( #' otherwise to random walk. #' @return A new prior specification PriorBSVARSIGN. #' @examples - #' # a prior for 3-variable example with one lag and stationary data - #' data(oil) - #' prior = specify_prior_bsvarSIGN$new(oil, p = 1) + #' # a prior for 5-variable example with one lag and stationary data + #' data(optimism) + #' prior = specify_prior_bsvarSIGN$new(optimism, p = 1) #' prior$B # show autoregressive prior mean #' initialize = function(data, p, exogenous = NULL, stationary = rep(FALSE, ncol(data))) { @@ -301,8 +301,8 @@ specify_prior_bsvarSIGN = R6::R6Class( #' Returns the elements of the prior specification PriorBSVAR as a \code{list}. #' #' @examples - #' # a prior for 3-variable example with four lags - #' prior = specify_prior_bsvar$new(N = 3, p = 4) + #' # a prior for 5-variable example with four lags + #' prior = specify_prior_bsvar$new(N = 5, p = 4) #' prior$get_prior() # show the prior as list #' get_prior = function(){ @@ -343,9 +343,9 @@ specify_prior_bsvarSIGN = R6::R6Class( #' @param burn_in number of burn-in draws. #' #' @examples - #' # a prior for 3-variable example with four lags - #' data(oil) - #' prior = specify_prior_bsvarSIGN$new(oil, p = 1) + #' # a prior for 5-variable example with four lags + #' data(optimism) + #' prior = specify_prior_bsvarSIGN$new(optimism, p = 1) #' prior$estimate_hyper(S = 5) #' estimate_hyper = function( @@ -404,11 +404,11 @@ specify_prior_bsvarSIGN = R6::R6Class( #' The class IdentificationBSVARSIGN presents the identifying restrictions for the Bayesian Structural VAR models with sign and narrative restrictions. #' #' @examples -#' specify_identification_bsvarSIGN$new(N = 3) # recursive specification for a 3-variable system +#' specify_identification_bsvarSIGN$new(N = 5) # recursive specification for a 5-variable system #' #' # an identification pattern with narrative sign restrictions -#' sign_narrative <- matrix(c(2, -1, 3, 2, 236, 0), ncol = 6) -#' specify_identification_bsvarSIGN$new(N = 3, sign_narrative = sign_narrative) +#' sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +#' specify_identification_bsvarSIGN$new(N = 5, sign_irf = sign_irf) #' #' @export specify_identification_bsvarSIGN = R6::R6Class( @@ -592,9 +592,9 @@ specify_identification_bsvarSIGN = R6::R6Class( #' @seealso \code{\link{estimate}}, \code{\link{specify_posterior_bsvarSIGN}} #' #' @examples -#' data(oil) +#' data(optimism) #' specification = specify_bsvarSIGN$new( -#' data = oil, +#' data = optimism, #' p = 4 #' ) #' @@ -718,9 +718,9 @@ specify_bsvarSIGN = R6::R6Class( #' Returns the data matrices as the DataMatricesBSVAR object. #' #' @examples - #' data(oil) + #' data(optimism) #' spec = specify_bsvarSIGN$new( - #' data = oil, + #' data = optimism, #' p = 4 #' ) #' spec$get_data_matrices() @@ -733,9 +733,9 @@ specify_bsvarSIGN = R6::R6Class( #' Returns the identifying restrictions as the IdentificationBSVARSIGN object. #' #' @examples - #' data(oil) + #' data(optimism) #' spec = specify_bsvarSIGN$new( - #' data = oil, + #' data = optimism, #' p = 4 #' ) #' spec$get_identification() @@ -748,9 +748,9 @@ specify_bsvarSIGN = R6::R6Class( #' Returns the prior specification as the PriorBSVAR object. #' #' @examples - #' data(oil) + #' data(optimism) #' spec = specify_bsvarSIGN$new( - #' data = oil, + #' data = optimism, #' p = 4 #' ) #' spec$get_prior() @@ -763,9 +763,9 @@ specify_bsvarSIGN = R6::R6Class( #' Returns the starting values as the StartingValuesBSVAR object. #' #' @examples - #' data(oil) + #' data(optimism) #' spec = specify_bsvarSIGN$new( - #' data = oil, + #' data = optimism, #' p = 4 #' ) #' spec$get_starting_values() @@ -790,8 +790,8 @@ specify_bsvarSIGN = R6::R6Class( #' #' @examples #' # This is a function that is used within estimate() -#' data(oil) -#' specification = specify_bsvarSIGN$new(oil, p = 4) +#' data(optimism) +#' specification = specify_bsvarSIGN$new(optimism, p = 4) #' set.seed(123) #' posterior = estimate(specification, 50) #' class(posterior) @@ -835,8 +835,8 @@ specify_posterior_bsvarSIGN = R6::R6Class( #' an \code{NxNxS} array \code{B}, an \code{NxKxS} array \code{A}, and a \code{5xS} matrix \code{hyper}. #' #' @examples - #' data(oil) - #' specification = specify_bsvarSIGN$new(oil) + #' data(optimism) + #' specification = specify_bsvarSIGN$new(optimism) #' set.seed(123) #' estimate = estimate(specification, 50) #' estimate$get_posterior() @@ -850,8 +850,8 @@ specify_posterior_bsvarSIGN = R6::R6Class( #' and \code{FALSE} otherwise. #' #' @examples - #' data(oil) - #' specification = specify_bsvarSIGN$new(oil) + #' data(optimism) + #' specification = specify_bsvarSIGN$new(optimism) #' set.seed(123) #' estimate = estimate(specification, 20) #' diff --git a/data/oil.rda b/data/oil.rda deleted file mode 100644 index cd1e14b..0000000 Binary files a/data/oil.rda and /dev/null differ diff --git a/inst/tinytest/test_compute_fitted_values.R b/inst/tinytest/test_compute_fitted_values.R index 17c1658..4e0209b 100644 --- a/inst/tinytest/test_compute_fitted_values.R +++ b/inst/tinytest/test_compute_fitted_values.R @@ -1,16 +1,16 @@ -data(oil) +data(optimism) set.seed(1) suppressMessages( - specification_no1 <- specify_bsvarSIGN$new(oil) + specification_no1 <- specify_bsvarSIGN$new(optimism) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) fv <- compute_fitted_values(run_no1) set.seed(1) suppressMessages( - fv2 <- oil |> + fv2 <- optimism |> specify_bsvarSIGN$new() |> estimate(S = 3, thin = 1, show_progress = FALSE) |> compute_fitted_values() diff --git a/inst/tinytest/test_compute_historical_decompositions.R b/inst/tinytest/test_compute_historical_decompositions.R index 865f7a1..a978412 100644 --- a/inst/tinytest/test_compute_historical_decompositions.R +++ b/inst/tinytest/test_compute_historical_decompositions.R @@ -1,16 +1,16 @@ -data(oil) +data(optimism) set.seed(1) suppressMessages( - specification_no1 <- specify_bsvarSIGN$new(oil) + specification_no1 <- specify_bsvarSIGN$new(optimism) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) hd <- compute_historical_decompositions(run_no1) set.seed(1) suppressMessages( - hd2 <- oil |> + hd2 <- optimism |> specify_bsvarSIGN$new() |> estimate(S = 3, thin = 1, show_progress = FALSE) |> compute_historical_decompositions() diff --git a/inst/tinytest/test_compute_impulse_responses.R b/inst/tinytest/test_compute_impulse_responses.R index 66c7b5a..a245d0d 100644 --- a/inst/tinytest/test_compute_impulse_responses.R +++ b/inst/tinytest/test_compute_impulse_responses.R @@ -1,16 +1,16 @@ -data(oil) +data(optimism) set.seed(1) suppressMessages( - specification_no1 <- specify_bsvarSIGN$new(oil) + specification_no1 <- specify_bsvarSIGN$new(optimism) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) irf <- compute_impulse_responses(run_no1, horizon = 2) set.seed(1) suppressMessages( - irf2 <- oil |> + irf2 <- optimism |> specify_bsvarSIGN$new() |> estimate(S = 3, thin = 1, show_progress = FALSE) |> compute_impulse_responses(horizon = 2) @@ -30,14 +30,14 @@ expect_identical( set.seed(1) suppressMessages( - specification_no1 <- specify_bsvarSIGN$new(oil) + specification_no1 <- specify_bsvarSIGN$new(optimism) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) irf <- compute_impulse_responses(run_no1, horizon = 2, standardise = TRUE) set.seed(1) suppressMessages( - irf2 <- oil |> + irf2 <- optimism |> specify_bsvarSIGN$new() |> estimate(S = 3, thin = 1, show_progress = FALSE) |> compute_impulse_responses(horizon = 2, standardise = TRUE) diff --git a/inst/tinytest/test_compute_structural_shocks.R b/inst/tinytest/test_compute_structural_shocks.R index 6f0a47e..3aa39b5 100644 --- a/inst/tinytest/test_compute_structural_shocks.R +++ b/inst/tinytest/test_compute_structural_shocks.R @@ -1,16 +1,16 @@ -data(oil) +data(optimism) set.seed(1) suppressMessages( - specification_no1 <- specify_bsvarSIGN$new(oil) + specification_no1 <- specify_bsvarSIGN$new(optimism) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) ss <- compute_structural_shocks(run_no1) set.seed(1) suppressMessages( - ss2 <- oil |> + ss2 <- optimism |> specify_bsvarSIGN$new() |> estimate(S = 3, thin = 1, show_progress = FALSE) |> compute_structural_shocks() diff --git a/inst/tinytest/test_compute_variance_decomposition.R b/inst/tinytest/test_compute_variance_decomposition.R index 2af4e9e..3d66e84 100644 --- a/inst/tinytest/test_compute_variance_decomposition.R +++ b/inst/tinytest/test_compute_variance_decomposition.R @@ -1,16 +1,16 @@ -data(oil) +data(optimism) set.seed(1) suppressMessages( - specification_no1 <- specify_bsvarSIGN$new(oil) + specification_no1 <- specify_bsvarSIGN$new(optimism) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) fevd <- compute_variance_decompositions(run_no1, horizon = 2) set.seed(1) suppressMessages( - fevd2 <- oil |> + fevd2 <- optimism |> specify_bsvarSIGN$new() |> estimate(S = 3, thin = 1, show_progress = FALSE) |> compute_variance_decompositions(horizon = 2) diff --git a/inst/tinytest/test_estimate.R b/inst/tinytest/test_estimate.R index b25a88d..3689831 100644 --- a/inst/tinytest/test_estimate.R +++ b/inst/tinytest/test_estimate.R @@ -3,8 +3,8 @@ # run 1 set.seed(123) -data(oil) -spec1 = specify_bsvarSIGN$new(oil) +data(optimism) +spec1 = specify_bsvarSIGN$new(optimism) post1 = estimate(spec1, S = 3, thin = 1, @@ -12,8 +12,8 @@ post1 = estimate(spec1, # run 2 set.seed(123) -data(oil) -spec2 = specify_bsvarSIGN$new(oil) +data(optimism) +spec2 = specify_bsvarSIGN$new(optimism) post2 = estimate(spec2, S = 3, thin = 1, @@ -21,8 +21,8 @@ post2 = estimate(spec2, # run 3 (pipe workflow) set.seed(123) -data(oil) -post3 = oil |> +data(optimism) +post3 = optimism |> specify_bsvarSIGN$new() |> estimate(S = 3, thin = 1, diff --git a/inst/tinytest/test_forecast.R b/inst/tinytest/test_forecast.R index edb132a..0f11183 100644 --- a/inst/tinytest/test_forecast.R +++ b/inst/tinytest/test_forecast.R @@ -1,17 +1,17 @@ -data(oil) +data(optimism) # for bsvar set.seed(1) suppressMessages( - specification_no1 <- specify_bsvarSIGN$new(oil, p = 1) + specification_no1 <- specify_bsvarSIGN$new(optimism, p = 1) ) run_no1 <- estimate(specification_no1, 3, 1, show_progress = FALSE) ff <- forecast(run_no1, horizon = 2) set.seed(1) suppressMessages( - ff2 <- oil |> + ff2 <- optimism |> specify_bsvarSIGN$new(p = 1) |> estimate(S = 3, thin = 1, show_progress = FALSE) |> forecast(horizon = 2) diff --git a/inst/tinytest/test_specify.R b/inst/tinytest/test_specify.R index dfc7886..0167ed4 100644 --- a/inst/tinytest/test_specify.R +++ b/inst/tinytest/test_specify.R @@ -1,9 +1,9 @@ # minimum example of specify_bsvarSIGN works -data(oil) +data(optimism) -spec = specify_bsvarSIGN$new(oil) +spec = specify_bsvarSIGN$new(optimism) expect_identical(class(spec)[1], "BSVARSIGN") @@ -35,18 +35,15 @@ expect_identical(class(spec$starting_values)[1], # "example specifying a reproduction of Antolín-Díaz & Rubio-Ramírez (2018, AER)", -data(oil) -sign_narrative = matrix(c(2, -1, 3, 2, 236, 0), ncol = 6) +data(optimism) -sign_irf = array(matrix(c(-1, -1, 1, 1, 1, 1, 1, -1, 1), nrow = 3), - dim = c(3, 3, 1)) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) set.seed(123) -spec = specify_bsvarSIGN$new(oil, +spec = specify_bsvarSIGN$new(optimism, p = 12, - sign_irf = sign_irf, - sign_narrative = sign_narrative) + sign_irf = sign_irf) expect_identical(class(spec)[1], "BSVARSIGN") diff --git a/man/bsvarSIGNs-package.Rd b/man/bsvarSIGNs-package.Rd index 22730b3..240ed71 100644 --- a/man/bsvarSIGNs-package.Rd +++ b/man/bsvarSIGNs-package.Rd @@ -17,9 +17,7 @@ This package is currently in active development. We give no warranty that anything here works. } \examples{ -sign_irf = matrix(NA, 5, 5) -sign_irf[2, 1] = 1 -sign_irf[1, 1] = 0 +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) spec = specify_bsvarSIGN$new(optimism * 100, p = 4, sign_irf = sign_irf) diff --git a/man/compute_conditional_sd.PosteriorBSVARSIGN.Rd b/man/compute_conditional_sd.PosteriorBSVARSIGN.Rd index c7ee5f4..22edb50 100644 --- a/man/compute_conditional_sd.PosteriorBSVARSIGN.Rd +++ b/man/compute_conditional_sd.PosteriorBSVARSIGN.Rd @@ -22,12 +22,12 @@ shock conditional standard deviations. } \examples{ # upload data -data(oil) +data(optimism) # specify the model and set seed set.seed(123) -sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) # run the burn-in posterior = estimate(specification, 10) @@ -38,7 +38,7 @@ sigma = compute_conditional_sd(posterior) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 10) |> compute_conditional_sd() -> csd diff --git a/man/compute_fitted_values.PosteriorBSVARSIGN.Rd b/man/compute_fitted_values.PosteriorBSVARSIGN.Rd index 2e139c8..65b908a 100644 --- a/man/compute_fitted_values.PosteriorBSVARSIGN.Rd +++ b/man/compute_fitted_values.PosteriorBSVARSIGN.Rd @@ -22,12 +22,12 @@ a draw from the data predictive density. } \examples{ # upload data -data(oil) +data(optimism) # specify the model and set seed set.seed(123) -sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) # run the burn-in posterior = estimate(specification, 10) @@ -38,7 +38,7 @@ fitted = compute_fitted_values(posterior) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 20) |> compute_fitted_values() -> fitted diff --git a/man/compute_historical_decompositions.PosteriorBSVARSIGN.Rd b/man/compute_historical_decompositions.PosteriorBSVARSIGN.Rd index f359efd..fbcf0ae 100644 --- a/man/compute_historical_decompositions.PosteriorBSVARSIGN.Rd +++ b/man/compute_historical_decompositions.PosteriorBSVARSIGN.Rd @@ -27,12 +27,12 @@ result in non-interpretable outcomes. } \examples{ # upload data -data(oil) +data(optimism) # specify the model and set seed set.seed(123) -sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) # run the burn-in posterior = estimate(specification, 10) @@ -43,7 +43,7 @@ hd = compute_historical_decompositions(posterior) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 10) |> compute_historical_decompositions() -> hd diff --git a/man/compute_impulse_responses.PosteriorBSVARSIGN.Rd b/man/compute_impulse_responses.PosteriorBSVARSIGN.Rd index afcf9f7..d2e72f7 100644 --- a/man/compute_impulse_responses.PosteriorBSVARSIGN.Rd +++ b/man/compute_impulse_responses.PosteriorBSVARSIGN.Rd @@ -27,12 +27,12 @@ a draw from the posterior distribution of the impulse responses. } \examples{ # upload data -data(oil) +data(optimism) # specify the model and set seed set.seed(123) -sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) # run the burn-in posterior = estimate(specification, 10) @@ -43,7 +43,7 @@ irf = compute_impulse_responses(posterior, horizon = 8) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 10) |> compute_impulse_responses(horizon = 8) -> ir diff --git a/man/compute_structural_shocks.PosteriorBSVARSIGN.Rd b/man/compute_structural_shocks.PosteriorBSVARSIGN.Rd index 13d634b..fa00833 100644 --- a/man/compute_structural_shocks.PosteriorBSVARSIGN.Rd +++ b/man/compute_structural_shocks.PosteriorBSVARSIGN.Rd @@ -22,12 +22,12 @@ a draw from the posterior distribution of the structural shocks. } \examples{ # upload data -data(oil) +data(optimism) # specify the model and set seed set.seed(123) -sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) # run the burn-in posterior = estimate(specification, 10) @@ -38,7 +38,7 @@ shocks = compute_structural_shocks(posterior) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 20) |> compute_structural_shocks() -> ss diff --git a/man/compute_variance_decompositions.PosteriorBSVARSIGN.Rd b/man/compute_variance_decompositions.PosteriorBSVARSIGN.Rd index 9f191c5..0d869ed 100644 --- a/man/compute_variance_decompositions.PosteriorBSVARSIGN.Rd +++ b/man/compute_variance_decompositions.PosteriorBSVARSIGN.Rd @@ -25,12 +25,12 @@ error variance decomposition. } \examples{ # upload data -data(oil) +data(optimism) # specify the model and set seed set.seed(123) -sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) # run the burn-in posterior = estimate(specification, 10) @@ -41,7 +41,7 @@ fevd = compute_variance_decompositions(posterior, horizon = 8) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 10) |> compute_variance_decompositions(horizon = 8) -> fevd diff --git a/man/estimate.BSVARSIGN.Rd b/man/estimate.BSVARSIGN.Rd index c681125..e487994 100644 --- a/man/estimate.BSVARSIGN.Rd +++ b/man/estimate.BSVARSIGN.Rd @@ -70,20 +70,15 @@ Finally, the structural shocks, \code{U}, are temporally and contemporaneously i } \examples{ # upload data -data(oil) +data(optimism) -# restrictions as in Antolín-Díaz & Rubio-Ramírez (2018) -sign_narrative = matrix(c(2, -1, 3, 2, 236, 0), ncol = 6) -sign_irf = array(matrix(c(-1, -1, 1, 1, 1, 1, 1, -1, 1), nrow = 3), - dim = c(3, 3, 1)) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) # specify the model and set seed set.seed(123) -specification = specify_bsvarSIGN$new(oil, - p = 12, - sign_irf = sign_irf, - sign_narrative = sign_narrative - ) +specification = specify_bsvarSIGN$new(optimism * 100, + p = 12, + sign_irf = sign_irf) posterior = estimate(specification, S = 10) } diff --git a/man/forecast.PosteriorBSVARSIGN.Rd b/man/forecast.PosteriorBSVARSIGN.Rd index a40cd2c..08477c0 100644 --- a/man/forecast.PosteriorBSVARSIGN.Rd +++ b/man/forecast.PosteriorBSVARSIGN.Rd @@ -44,12 +44,12 @@ trajcetories of (some of the) variables. } \examples{ # upload data -data(oil) +data(optimism) # specify the model and set seed set.seed(123) -sign_irf = array(matrix(c(-1, -1, 1, rep(NA, 6)), nrow = 3), dim = c(3, 3, 1)) -specification = specify_bsvarSIGN$new(oil, sign_irf = sign_irf) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specification = specify_bsvarSIGN$new(optimism, sign_irf = sign_irf) # estimate the model posterior = estimate(specification, 20) @@ -60,7 +60,7 @@ predictive = forecast(posterior, 4) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 20) |> forecast(horizon = 4) -> predictive @@ -68,14 +68,15 @@ oil |> # conditional forecasting 2 quarters ahead conditioning on # provided future values for the Gross Domestic Product ############################################################ -cf = matrix(NA , 2, 3) -cf[,3] = tail(oil, 1)[3] # conditional forecasts equal to the last gdp observation -predictive = forecast(posterior, 2, conditional_forecast = cf) +cf = matrix(NA , 2, 5) +# # conditional forecasts equal to the last consumption observation +cf[,3] = tail(optimism, 1)[3] +predictive = forecast(posterior, 2, conditional_forecast = cf) # workflow with the pipe |> ############################################################ set.seed(123) -oil |> +optimism |> specify_bsvarSIGN$new(sign_irf = sign_irf) |> estimate(S = 10) |> forecast(horizon = 2, conditional_forecast = cf) -> predictive diff --git a/man/oil.Rd b/man/oil.Rd deleted file mode 100644 index fde0b58..0000000 --- a/man/oil.Rd +++ /dev/null @@ -1,29 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\name{oil} -\alias{oil} -\title{A 3-variable oil price data, from 1971 to 2016} -\format{ -A matrix and a \code{ts} object with time series of over five hundred observations on 3 variables: -\describe{ - \item{opg}{monthly growth rate of global oil production} - \item{eai}{monthly index of real economic activity} - \item{rop}{monthly real oil price} -} - -The series are as described by Antolín-Díaz & Rubio-Ramírez (2018) in section IV-A. -} -\source{ -Replication package, \url{https://www.aeaweb.org/articles?id=10.1257/aer.20161852} -} -\usage{ -data(oil) -} -\description{ -A sample data to identify oil demand and supply shocks. -} -\references{ -Antolín-Díaz & Rubio-Ramírez (2018) Narrative Sign Restrictions for SVARs, American Economic Review, 108(10), 2802-29, . -} -\keyword{datasets} diff --git a/man/specify_bsvarSIGN.Rd b/man/specify_bsvarSIGN.Rd index 3f937f3..a72068a 100644 --- a/man/specify_bsvarSIGN.Rd +++ b/man/specify_bsvarSIGN.Rd @@ -7,9 +7,9 @@ The class BSVARSIGN presents complete specification for the Bayesian Structural VAR model with sign and narrative restrictions. } \examples{ -data(oil) +data(optimism) specification = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) @@ -18,9 +18,9 @@ specification = specify_bsvarSIGN$new( ## Method `specify_bsvarSIGN$get_data_matrices` ## ------------------------------------------------ -data(oil) +data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_data_matrices() @@ -30,9 +30,9 @@ spec$get_data_matrices() ## Method `specify_bsvarSIGN$get_identification` ## ------------------------------------------------ -data(oil) +data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_identification() @@ -42,9 +42,9 @@ spec$get_identification() ## Method `specify_bsvarSIGN$get_prior` ## ------------------------------------------------ -data(oil) +data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_prior() @@ -54,9 +54,9 @@ spec$get_prior() ## Method `specify_bsvarSIGN$get_starting_values` ## ------------------------------------------------ -data(oil) +data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_starting_values() @@ -170,9 +170,9 @@ Returns the data matrices as the DataMatricesBSVAR object. \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{data(oil) +\preformatted{data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_data_matrices() @@ -194,9 +194,9 @@ Returns the identifying restrictions as the IdentificationBSVARSIGN object. \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{data(oil) +\preformatted{data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_identification() @@ -218,9 +218,9 @@ Returns the prior specification as the PriorBSVAR object. \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{data(oil) +\preformatted{data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_prior() @@ -242,9 +242,9 @@ Returns the starting values as the StartingValuesBSVAR object. \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{data(oil) +\preformatted{data(optimism) spec = specify_bsvarSIGN$new( - data = oil, + data = optimism, p = 4 ) spec$get_starting_values() diff --git a/man/specify_identification_bsvarSIGN.Rd b/man/specify_identification_bsvarSIGN.Rd index c1ab0ec..0bbc9b2 100644 --- a/man/specify_identification_bsvarSIGN.Rd +++ b/man/specify_identification_bsvarSIGN.Rd @@ -7,11 +7,11 @@ The class IdentificationBSVARSIGN presents the identifying restrictions for the Bayesian Structural VAR models with sign and narrative restrictions. } \examples{ -specify_identification_bsvarSIGN$new(N = 3) # recursive specification for a 3-variable system +specify_identification_bsvarSIGN$new(N = 5) # recursive specification for a 5-variable system # an identification pattern with narrative sign restrictions -sign_narrative <- matrix(c(2, -1, 3, 2, 236, 0), ncol = 6) -specify_identification_bsvarSIGN$new(N = 3, sign_narrative = sign_narrative) +sign_irf = matrix(c(0, 1, rep(NA, 23)), 5, 5) +specify_identification_bsvarSIGN$new(N = 5, sign_irf = sign_irf) } \section{Public fields}{ diff --git a/man/specify_posterior_bsvarSIGN.Rd b/man/specify_posterior_bsvarSIGN.Rd index 9b79415..fafa028 100644 --- a/man/specify_posterior_bsvarSIGN.Rd +++ b/man/specify_posterior_bsvarSIGN.Rd @@ -11,8 +11,8 @@ might not be equal to the last draw provided in element \code{posterior}. } \examples{ # This is a function that is used within estimate() -data(oil) -specification = specify_bsvarSIGN$new(oil, p = 4) +data(optimism) +specification = specify_bsvarSIGN$new(optimism, p = 4) set.seed(123) posterior = estimate(specification, 50) class(posterior) @@ -22,8 +22,8 @@ class(posterior) ## Method `specify_posterior_bsvarSIGN$get_posterior` ## ------------------------------------------------ -data(oil) -specification = specify_bsvarSIGN$new(oil) +data(optimism) +specification = specify_bsvarSIGN$new(optimism) set.seed(123) estimate = estimate(specification, 50) estimate$get_posterior() @@ -33,8 +33,8 @@ estimate$get_posterior() ## Method `specify_posterior_bsvarSIGN$is_normalised` ## ------------------------------------------------ -data(oil) -specification = specify_bsvarSIGN$new(oil) +data(optimism) +specification = specify_bsvarSIGN$new(optimism) set.seed(123) estimate = estimate(specification, 20) @@ -101,8 +101,8 @@ an \code{NxNxS} array \code{B}, an \code{NxKxS} array \code{A}, and a \code{5xS} \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{data(oil) -specification = specify_bsvarSIGN$new(oil) +\preformatted{data(optimism) +specification = specify_bsvarSIGN$new(optimism) set.seed(123) estimate = estimate(specification, 50) estimate$get_posterior() @@ -125,8 +125,8 @@ and \code{FALSE} otherwise. \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{data(oil) -specification = specify_bsvarSIGN$new(oil) +\preformatted{data(optimism) +specification = specify_bsvarSIGN$new(optimism) set.seed(123) estimate = estimate(specification, 20) diff --git a/man/specify_prior_bsvarSIGN.Rd b/man/specify_prior_bsvarSIGN.Rd index f6ea882..9b9e437 100644 --- a/man/specify_prior_bsvarSIGN.Rd +++ b/man/specify_prior_bsvarSIGN.Rd @@ -7,19 +7,19 @@ The class PriorBSVARSIGN presents a prior specification for the homoskedastic bsvar model. } \examples{ -# a prior for 3-variable example with one lag -data(oil) -prior = specify_prior_bsvarSIGN$new(oil, p = 1) -prior$B # show autoregressive prior mean +# a prior for 5-variable example with one lag +data(optimism) +prior = specify_prior_bsvarSIGN$new(optimism, p = 1) +prior$A # show autoregressive prior mean ## ------------------------------------------------ ## Method `specify_prior_bsvarSIGN$new` ## ------------------------------------------------ -# a prior for 3-variable example with one lag and stationary data -data(oil) -prior = specify_prior_bsvarSIGN$new(oil, p = 1) +# a prior for 5-variable example with one lag and stationary data +data(optimism) +prior = specify_prior_bsvarSIGN$new(optimism, p = 1) prior$B # show autoregressive prior mean @@ -27,8 +27,8 @@ prior$B # show autoregressive prior mean ## Method `specify_prior_bsvarSIGN$get_prior` ## ------------------------------------------------ -# a prior for 3-variable example with four lags -prior = specify_prior_bsvar$new(N = 3, p = 4) +# a prior for 5-variable example with four lags +prior = specify_prior_bsvar$new(N = 5, p = 4) prior$get_prior() # show the prior as list @@ -36,9 +36,9 @@ prior$get_prior() # show the prior as list ## Method `specify_prior_bsvarSIGN$estimate_hyper` ## ------------------------------------------------ -# a prior for 3-variable example with four lags -data(oil) -prior = specify_prior_bsvarSIGN$new(oil, p = 1) +# a prior for 5-variable example with four lags +data(optimism) +prior = specify_prior_bsvarSIGN$new(optimism, p = 1) prior$estimate_hyper(S = 5) } @@ -136,9 +136,9 @@ A new prior specification PriorBSVARSIGN. } \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{# a prior for 3-variable example with one lag and stationary data -data(oil) -prior = specify_prior_bsvarSIGN$new(oil, p = 1) +\preformatted{# a prior for 5-variable example with one lag and stationary data +data(optimism) +prior = specify_prior_bsvarSIGN$new(optimism, p = 1) prior$B # show autoregressive prior mean } @@ -158,8 +158,8 @@ Returns the elements of the prior specification PriorBSVAR as a \code{list}. \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{# a prior for 3-variable example with four lags -prior = specify_prior_bsvar$new(N = 3, p = 4) +\preformatted{# a prior for 5-variable example with four lags +prior = specify_prior_bsvar$new(N = 5, p = 4) prior$get_prior() # show the prior as list } @@ -207,9 +207,9 @@ variances in the Minnesota prior.} } \subsection{Examples}{ \if{html}{\out{
}} -\preformatted{# a prior for 3-variable example with four lags -data(oil) -prior = specify_prior_bsvarSIGN$new(oil, p = 1) +\preformatted{# a prior for 5-variable example with four lags +data(optimism) +prior = specify_prior_bsvarSIGN$new(optimism, p = 1) prior$estimate_hyper(S = 5) }