R Under development (unstable) (2026-01-28 r89343) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pkgname <- "bayesianVARs" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('bayesianVARs') > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("bvar") > ### * bvar > > flush(stderr()); flush(stdout()) > > ### Name: bvar > ### Title: Markov Chain Monte Carlo Sampling for Bayesian > ### Vectorautoregressions > ### Aliases: bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Plot > plot(mod) > > # Summary > summary(mod) Posterior median of reduced-form coefficients: GDPC1 CPIAUCSL FEDFUNDS GDPC1.l1 0.216 0.000 0.030 CPIAUCSL.l1 -0.044 0.613 -0.002 FEDFUNDS.l1 0.009 0.039 1.000 intercept 0.006 0.001 0.000 Posterior interquartile range of of reduced-form coefficients: GDPC1 CPIAUCSL FEDFUNDS GDPC1.l1 0.096 0.030 0.025 CPIAUCSL.l1 0.100 0.086 0.015 FEDFUNDS.l1 0.017 0.013 0.007 intercept 0.001 0.001 0.000 Posterior median of factor loadings: factor1 GDPC1 0 CPIAUCSL 0 FEDFUNDS 0 Posterior interquartile range of factor loadings: factor1 GDPC1 0.001 CPIAUCSL 0.000 FEDFUNDS 0.000 > > > > > cleanEx() > nameEx("coef") > ### * coef > > flush(stderr()); flush(stdout()) > > ### Name: coef > ### Title: Extract VAR coefficients > ### Aliases: coef coef.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Extract posterior draws of VAR coefficients > bvar_coefs <- coef(mod) > > > > cleanEx() > nameEx("extractB0") > ### * extractB0 > > flush(stderr()); flush(stdout()) > > ### Name: extractB0 > ### Title: Retrieve the structural parameter \boldsymbol{B}_0 samples from > ### an IRF object. > ### Aliases: extractB0 > > ### ** Examples > > train_data <- 100 * usmacro_growth[,c("GDPC1", "GDPCTPI", "GS1", "M2REAL", "CPIAUCSL")] > prior_sigma <- specify_prior_sigma(train_data, type="cholesky", cholesky_heteroscedastic=FALSE) Since argument 'type' is specified with 'cholesky', all arguments starting with 'factor_' are being ignored. Argument 'cholesky_priorhomoscedastic' not specified. Setting both shape and rate of inverse gamma prior equal to 0.01. > mod <- bvar(train_data, lags=5L, prior_sigma=prior_sigma, quiet=TRUE) > > structural_restrictions <- specify_structural_restrictions( + mod, + restrictions_B0=rbind( + c(1 ,NA,0 ,NA,NA), + c(0 ,1 ,0 ,NA,NA), + c(0 ,NA,1 ,NA,NA), + c(0 ,0 ,NA,1 ,NA), + c(0 ,0 ,0 ,0 ,1 ) + ) + ) > irf_structural <- irf( + mod, ahead=8, + structural_restrictions=structural_restrictions + ) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:59:10: runtime error: nan is outside the range of representable values of type 'int' #0 0x7fbb6e775472 in Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::equal<14>, true, Rcpp::ConstMatrixColumn<14>>::rhs_is_not_na(int) const /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:59:10 #1 0x7fbb6e7756cc in Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::equal<14>, true, Rcpp::ConstMatrixColumn<14>>::operator[](long) const /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:45:10 #2 0x7fbb6e7756cc in void Rcpp::Vector<10, Rcpp::PreserveStorage>::import_expression, true, Rcpp::ConstMatrixColumn<14>>>(Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::equal<14>, true, Rcpp::ConstMatrixColumn<14>> const&, long) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/vector/Vector.h:1082:9 #3 0x7fbb6e761ee0 in Rcpp::Vector<10, Rcpp::PreserveStorage>::Vector, true, Rcpp::ConstMatrixColumn<14>>>(Rcpp::VectorBase<10, true, Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::equal<14>, true, Rcpp::ConstMatrixColumn<14>>> const&) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/vector/Vector.h:164:9 #4 0x7fbb6e761ee0 in construct_zero_restriction(Rcpp::ConstMatrixColumn<14> const&) /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/irf.cpp:126:37 #5 0x7fbb6e762b2c in find_rotation_cpp(arma::field> const&, arma::field> const&, std::__1::basic_string, std::__1::allocator> const&, unsigned int, double) /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/irf.cpp:391:30 #6 0x7fbb6e71c2c8 in _bayesianVARs_find_rotation_cpp /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/RcppExports.cpp:85:34 #7 0x563bd55b03fa in R_doDotCall (/data/gannet/ripley/R/R-clang/bin/exec/R+0x8f3fa) #8 0x563bd55fedaf in bcEval_loop eval.c #9 0x563bd55e7beb in bcEval eval.c #10 0x563bd55e7374 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc6374) #11 0x563bd5604768 in R_execClosure eval.c #12 0x563bd5603c6b in applyClosure_core eval.c #13 0x563bd55e77c5 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc67c5) #14 0x563bd5609d6d in do_set (/data/gannet/ripley/R/R-clang/bin/exec/R+0xe8d6d) #15 0x563bd55e759f in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc659f) #16 0x563bd5639717 in Rf_ReplIteration (/data/gannet/ripley/R/R-clang/bin/exec/R+0x118717) #17 0x563bd563b21e in run_Rmainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a21e) #18 0x563bd563b28a in Rf_mainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a28a) #19 0x563bd5522da7 in main (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1da7) #20 0x7fbb7f1135f4 in __libc_start_call_main (/lib64/libc.so.6+0x35f4) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #21 0x7fbb7f1136a7 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x36a7) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #22 0x563bd5522cc4 in _start (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1cc4) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:59:10 /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:59:10: runtime error: nan is outside the range of representable values of type 'int' #0 0x7fbb6e775e62 in Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::not_equal<14>, true, Rcpp::ConstMatrixColumn<14>>::rhs_is_not_na(int) const /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:59:10 #1 0x7fbb6e775fbc in Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::not_equal<14>, true, Rcpp::ConstMatrixColumn<14>>::operator[](long) const /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:45:10 #2 0x7fbb6e775fbc in void Rcpp::Vector<10, Rcpp::PreserveStorage>::import_expression, true, Rcpp::ConstMatrixColumn<14>>>(Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::not_equal<14>, true, Rcpp::ConstMatrixColumn<14>> const&, long) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/vector/Vector.h:1082:9 #3 0x7fbb6e762193 in Rcpp::Vector<10, Rcpp::PreserveStorage>::Vector, true, Rcpp::ConstMatrixColumn<14>>>(Rcpp::VectorBase<10, true, Rcpp::sugar::Comparator_With_One_Value<14, Rcpp::sugar::not_equal<14>, true, Rcpp::ConstMatrixColumn<14>>> const&) /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/vector/Vector.h:164:9 #4 0x7fbb6e762193 in construct_sign_restriction(Rcpp::ConstMatrixColumn<14> const&) /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/irf.cpp:140:42 #5 0x7fbb6e762d98 in find_rotation_cpp(arma::field> const&, arma::field> const&, std::__1::basic_string, std::__1::allocator> const&, unsigned int, double) /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/irf.cpp:392:30 #6 0x7fbb6e71c2c8 in _bayesianVARs_find_rotation_cpp /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/RcppExports.cpp:85:34 #7 0x563bd55b03fa in R_doDotCall (/data/gannet/ripley/R/R-clang/bin/exec/R+0x8f3fa) #8 0x563bd55fedaf in bcEval_loop eval.c #9 0x563bd55e7beb in bcEval eval.c #10 0x563bd55e7374 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc6374) #11 0x563bd5604768 in R_execClosure eval.c #12 0x563bd5603c6b in applyClosure_core eval.c #13 0x563bd55e77c5 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc67c5) #14 0x563bd5609d6d in do_set (/data/gannet/ripley/R/R-clang/bin/exec/R+0xe8d6d) #15 0x563bd55e759f in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc659f) #16 0x563bd5639717 in Rf_ReplIteration (/data/gannet/ripley/R/R-clang/bin/exec/R+0x118717) #17 0x563bd563b21e in run_Rmainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a21e) #18 0x563bd563b28a in Rf_mainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a28a) #19 0x563bd5522da7 in main (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1da7) #20 0x7fbb7f1135f4 in __libc_start_call_main (/lib64/libc.so.6+0x35f4) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #21 0x7fbb7f1136a7 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x36a7) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #22 0x563bd5522cc4 in _start (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1cc4) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /data/gannet/ripley/R/test-clang/Rcpp/include/Rcpp/sugar/operators/Comparator_With_One_Value.h:59:10 /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:7005:10: runtime error: reference binding to null pointer of type 'const double' #0 0x7fbb6e6fd6aa in arma::Mat::at(unsigned int, unsigned int) const /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:7005:3 #1 0x7fbb6e6fd6aa in void arma::op_strans::apply_mat_noalias>(arma::Mat&, arma::Mat const&) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/op_strans_meat.hpp:208:30 #2 0x7fbb6e763875 in void arma::op_strans::apply_direct, arma::subview>>(arma::Mat_noalias, arma::subview>::elem_type>&, arma::subview_elem2, arma::subview> const&) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/op_strans_meat.hpp:445:5 #3 0x7fbb6e763875 in void arma::op_htrans::apply, arma::subview>>(arma::Mat_noalias, arma::subview>::elem_type>&, arma::Op, arma::subview>, arma::op_htrans> const&, arma::arma_not_cx, arma::subview>::elem_type>::result const*) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/op_htrans_meat.hpp:388:3 #4 0x7fbb6e763875 in arma::Mat::Mat, arma::subview>, arma::op_htrans>(arma::Op, arma::subview>, arma::op_htrans> const&) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:5309:3 #5 0x7fbb6e763875 in find_rotation_cpp(arma::field> const&, arma::field> const&, std::__1::basic_string, std::__1::allocator> const&, unsigned int, double) /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/irf.cpp:412:27 #6 0x7fbb6e71c2c8 in _bayesianVARs_find_rotation_cpp /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/RcppExports.cpp:85:34 #7 0x563bd55b03fa in R_doDotCall (/data/gannet/ripley/R/R-clang/bin/exec/R+0x8f3fa) #8 0x563bd55fedaf in bcEval_loop eval.c #9 0x563bd55e7beb in bcEval eval.c #10 0x563bd55e7374 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc6374) #11 0x563bd5604768 in R_execClosure eval.c #12 0x563bd5603c6b in applyClosure_core eval.c #13 0x563bd55e77c5 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc67c5) #14 0x563bd5609d6d in do_set (/data/gannet/ripley/R/R-clang/bin/exec/R+0xe8d6d) #15 0x563bd55e759f in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc659f) #16 0x563bd5639717 in Rf_ReplIteration (/data/gannet/ripley/R/R-clang/bin/exec/R+0x118717) #17 0x563bd563b21e in run_Rmainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a21e) #18 0x563bd563b28a in Rf_mainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a28a) #19 0x563bd5522da7 in main (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1da7) #20 0x7fbb7f1135f4 in __libc_start_call_main (/lib64/libc.so.6+0x35f4) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #21 0x7fbb7f1136a7 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x36a7) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #22 0x563bd5522cc4 in _start (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1cc4) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:7005:10 /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:7005:10: runtime error: applying non-zero offset 8 to null pointer #0 0x7fbb6e6fd668 in arma::Mat::at(unsigned int, unsigned int) const /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:7005:10 #1 0x7fbb6e6fd668 in void arma::op_strans::apply_mat_noalias>(arma::Mat&, arma::Mat const&) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/op_strans_meat.hpp:208:30 #2 0x7fbb6e763875 in void arma::op_strans::apply_direct, arma::subview>>(arma::Mat_noalias, arma::subview>::elem_type>&, arma::subview_elem2, arma::subview> const&) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/op_strans_meat.hpp:445:5 #3 0x7fbb6e763875 in void arma::op_htrans::apply, arma::subview>>(arma::Mat_noalias, arma::subview>::elem_type>&, arma::Op, arma::subview>, arma::op_htrans> const&, arma::arma_not_cx, arma::subview>::elem_type>::result const*) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/op_htrans_meat.hpp:388:3 #4 0x7fbb6e763875 in arma::Mat::Mat, arma::subview>, arma::op_htrans>(arma::Op, arma::subview>, arma::op_htrans> const&) /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:5309:3 #5 0x7fbb6e763875 in find_rotation_cpp(arma::field> const&, arma::field> const&, std::__1::basic_string, std::__1::allocator> const&, unsigned int, double) /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/irf.cpp:412:27 #6 0x7fbb6e71c2c8 in _bayesianVARs_find_rotation_cpp /data/gannet/ripley/R/packages/tests-clang-UBSAN/bayesianVARs/src/RcppExports.cpp:85:34 #7 0x563bd55b03fa in R_doDotCall (/data/gannet/ripley/R/R-clang/bin/exec/R+0x8f3fa) #8 0x563bd55fedaf in bcEval_loop eval.c #9 0x563bd55e7beb in bcEval eval.c #10 0x563bd55e7374 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc6374) #11 0x563bd5604768 in R_execClosure eval.c #12 0x563bd5603c6b in applyClosure_core eval.c #13 0x563bd55e77c5 in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc67c5) #14 0x563bd5609d6d in do_set (/data/gannet/ripley/R/R-clang/bin/exec/R+0xe8d6d) #15 0x563bd55e759f in Rf_eval (/data/gannet/ripley/R/R-clang/bin/exec/R+0xc659f) #16 0x563bd5639717 in Rf_ReplIteration (/data/gannet/ripley/R/R-clang/bin/exec/R+0x118717) #17 0x563bd563b21e in run_Rmainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a21e) #18 0x563bd563b28a in Rf_mainloop (/data/gannet/ripley/R/R-clang/bin/exec/R+0x11a28a) #19 0x563bd5522da7 in main (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1da7) #20 0x7fbb7f1135f4 in __libc_start_call_main (/lib64/libc.so.6+0x35f4) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #21 0x7fbb7f1136a7 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x36a7) (BuildId: a1dda014206b55b07f58fe8db80121b752dc3d03) #22 0x563bd5522cc4 in _start (/data/gannet/ripley/R/R-clang/bin/exec/R+0x1cc4) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /data/gannet/ripley/R/test-clang/RcppArmadillo/include/current/armadillo_bits/Mat_meat.hpp:7005:10 > > B0 <- extractB0(irf_structural) > > # Visually check that the restriction B0[1,1] >= 0 has been satisfied > hist( + B0[1,1,], + xlim=range(0, B0), + main = paste0("Posterior B0[", 1, ",", 1,"]") + ) > abline(v=0, col=2, lwd=2) > > > > cleanEx() > nameEx("fitted.bayesianVARs_bvar") > ### * fitted.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: fitted.bayesianVARs_bvar > ### Title: Simulate fitted/predicted historical values for an estimated VAR > ### model > ### Aliases: fitted.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Simulate predicted historical values including the error term. > pred <- fitted(mod, error_term = TRUE) > > # Simulate fitted historical values not including the error term. > fit <- fitted(mod, error_term = FALSE) > > # Visualize > plot(pred) > plot(fit) > > > > cleanEx() > nameEx("irf") > ### * irf > > flush(stderr()); flush(stdout()) > > ### Name: irf > ### Title: Impulse response functions > ### Aliases: irf > > ### ** Examples > > train_data <- 100 * usmacro_growth[,c("GDPC1", "GDPCTPI", "GS1", "M2REAL", "CPIAUCSL")] > prior_sigma <- specify_prior_sigma(train_data, type="cholesky", cholesky_heteroscedastic=FALSE) Since argument 'type' is specified with 'cholesky', all arguments starting with 'factor_' are being ignored. Argument 'cholesky_priorhomoscedastic' not specified. Setting both shape and rate of inverse gamma prior equal to 0.01. > mod <- bvar(train_data, lags=5L, prior_sigma=prior_sigma, quiet=TRUE) > > structural_restrictions <- specify_structural_restrictions( + mod, + restrictions_B0=rbind( + c(1 ,NA,0 ,NA,NA), + c(0 ,1 ,0 ,NA,NA), + c(0 ,NA,1 ,NA,NA), + c(0 ,0 ,NA,1 ,NA), + c(0 ,0 ,0 ,0 ,1 ) + ) + ) > irf_structural <- irf( + mod, ahead=8, + structural_restrictions=structural_restrictions + ) > plot(irf_structural) > > > > > cleanEx() > nameEx("my_gig") > ### * my_gig > > flush(stderr()); flush(stdout()) > > ### Name: my_gig > ### Title: Draw from generalized inverse Gaussian > ### Aliases: my_gig > > ### ** Examples > > gigsamples <- my_gig(2, c(1,1), c(1,1), c(1,1)) > > > > cleanEx() > nameEx("pairs_predict") > ### * pairs_predict > > flush(stderr()); flush(stdout()) > > ### Name: pairs_predict > ### Title: Pairwise visualization of out-of-sample posterior predictive > ### densities. > ### Aliases: pairs_predict pairs.bayesianVARs_predict > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Simulate from posterior predictive > predictions <- predict(mod, ahead = 1:3) 'stable=TRUE': Calling 'stable_bvar()' to discard those posterior draws that do not fulfill the stable criterion. 500/1000 stable posterior draws remaining for prediction! > > # Visualize > pairs(predictions, vars = 1:3, ahead = 1:3) > > > > cleanEx() > nameEx("plot.bayesianVARs_bvar") > ### * plot.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: plot.bayesianVARs_bvar > ### Title: Plot method for bayesianVARs_bvar > ### Aliases: plot.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Simulate from posterior predictive > predictions <- predict(mod, ahead = 1:3) 'stable=TRUE': Calling 'stable_bvar()' to discard those posterior draws that do not fulfill the stable criterion. 500/1000 stable posterior draws remaining for prediction! > > # Visualize > plot(mod, predictions = predictions) > > > > cleanEx() > nameEx("plot.bayesianVARs_fitted") > ### * plot.bayesianVARs_fitted > > flush(stderr()); flush(stdout()) > > ### Name: plot.bayesianVARs_fitted > ### Title: Visualization of in-sample fit of an estimated VAR. > ### Aliases: plot.bayesianVARs_fitted > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Simulate predicted historical values including the error term. > pred <- fitted(mod, error_term = TRUE) > > # Visualize > plot(pred) > > > > cleanEx() > nameEx("plot.bayesianVARs_predict") > ### * plot.bayesianVARs_predict > > flush(stderr()); flush(stdout()) > > ### Name: plot.bayesianVARs_predict > ### Title: Fan chart > ### Aliases: plot.bayesianVARs_predict > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Simulate from posterior predictive > predictions <- predict(mod, ahead = 1:3) 'stable=TRUE': Calling 'stable_bvar()' to discard those posterior draws that do not fulfill the stable criterion. 500/1000 stable posterior draws remaining for prediction! > > # Visualize > plot(predictions, vars = 1:3, ahead = 1:3) > > > > cleanEx() > nameEx("plot.bayesianVARs_residuals") > ### * plot.bayesianVARs_residuals > > flush(stderr()); flush(stdout()) > > ### Name: plot.bayesianVARs_residuals > ### Title: Visualization of the residuals of an estimated VAR. > ### Aliases: plot.bayesianVARs_residuals > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > mod.resids <- residuals(mod) > > # Visualize > plot(mod.resids) > > > > cleanEx() > nameEx("posterior_heatmap") > ### * posterior_heatmap > > flush(stderr()); flush(stdout()) > > ### Name: posterior_heatmap > ### Title: Posterior heatmaps for matrix valued parameters > ### Aliases: posterior_heatmap > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(100*data, sv_keep = "all", quiet = TRUE) > > # Extract posterior draws of VAR coefficients > phi_post <- coef(mod) > > # Visualize posterior median of VAR coefficients > posterior_heatmap(phi_post, median, detect_lags = TRUE, border_color = rgb(0, 0, 0, alpha = 0.2)) > > # Extract posterior draws of variance-covariance matrices (for each point in time) > sigma_post <- vcov(mod) > # Visualize posterior interquartile-range of variance-covariance matrix of the first observation > posterior_heatmap(sigma_post[1,,,], IQR) > > > > cleanEx() > nameEx("predict.bayesianVARs_bvar") > ### * predict.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: predict.bayesianVARs_bvar > ### Title: Predict method for Bayesian VARs > ### Aliases: predict.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Split data in train and test > train <- data[1:(nrow(data)-4),] > test <- data[-c(1:(nrow(data)-4)),] > > # Estimate model using train data only > mod <- bvar(train, quiet = TRUE) > > # Simulate from 1-step to 4-steps ahead posterior predictive and compute > # log-predictive-likelihoods > predictions <- predict(mod, ahead = 1:4, LPL = TRUE, Y_obs = test) 'stable=TRUE': Calling 'stable_bvar()' to discard those posterior draws that do not fulfill the stable criterion. 548/1000 stable posterior draws remaining for prediction! > > # Summary > summary(predictions) LPL: t+1 t+2 t+3 t+4 3.058 8.833 8.717 6.410 Marginal univariate LPLs: GDPC1 CPIAUCSL FEDFUNDS t+1 -1.030 0.3174 3.627 t+2 2.777 2.6497 3.327 t+3 2.945 2.5317 3.147 t+4 3.040 0.4317 3.019 Prediction quantiles: , , GDPC1 t+1 t+2 t+3 t+4 5% -0.06878 -0.0407955 -0.030663 -0.02890 50% -0.01928 0.0008002 0.005585 0.00615 95% 0.03404 0.0450897 0.043113 0.03921 , , CPIAUCSL t+1 t+2 t+3 t+4 5% -0.021308 -0.019522 -0.017185 -0.015686 50% -0.008066 -0.005256 -0.003209 -0.001269 95% 0.004156 0.008746 0.009077 0.010302 , , FEDFUNDS t+1 t+2 t+3 t+4 5% -0.022105 -0.034334 -0.036658 -0.048157 50% -0.004185 -0.004556 -0.005207 -0.006438 95% 0.014476 0.026700 0.025326 0.034886 > > # Visualize via fan-charts > plot(predictions) > > > > > cleanEx() > nameEx("print.bayesianVARs_bvar") > ### * print.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: print.bayesianVARs_bvar > ### Title: Pretty printing of a bvar object > ### Aliases: print.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Print model > mod Fitted bayesianVARs_bvar object with - 3 series - 1 lag(s) - 246 used observations - 247 total observations - 1000 MCMC draws - 1 thinning - 1000 burn-in > > > > > cleanEx() > nameEx("print.bayesianVARs_predict") > ### * print.bayesianVARs_predict > > flush(stderr()); flush(stdout()) > > ### Name: print.bayesianVARs_predict > ### Title: Print method for bayesianVARs_predict objects > ### Aliases: print.bayesianVARs_predict > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Split data in train and test > train <- data[1:(nrow(data)-4),] > test <- data[-c(1:(nrow(data)-4)),] > > # Estimate model using train data only > mod <- bvar(train, quiet = TRUE) > > # Simulate from 1-step ahead posterior predictive > predictions <- predict(mod, ahead = 1L) 'stable=TRUE': Calling 'stable_bvar()' to discard those posterior draws that do not fulfill the stable criterion. 548/1000 stable posterior draws remaining for prediction! > print(predictions) Generic functions for bayesianVARs_predict objects: - summary.bayesianVARs_predict(), - pairs.bayesianVARs_predict(), - plot.bayesianVARs_predict() (alias for pairs.bayesianVARs_predict()). > > > > cleanEx() > nameEx("print.summary.bayesianVARs_bvar") > ### * print.summary.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: print.summary.bayesianVARs_bvar > ### Title: Print method for summary.bayesianVARs_bvar objects > ### Aliases: print.summary.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate model > mod <- bvar(data, quiet = TRUE) > > # Print summary > summary(mod) Posterior median of reduced-form coefficients: GDPC1 CPIAUCSL FEDFUNDS GDPC1.l1 0.216 0.000 0.030 CPIAUCSL.l1 -0.044 0.613 -0.002 FEDFUNDS.l1 0.009 0.039 1.000 intercept 0.006 0.001 0.000 Posterior interquartile range of of reduced-form coefficients: GDPC1 CPIAUCSL FEDFUNDS GDPC1.l1 0.096 0.030 0.025 CPIAUCSL.l1 0.100 0.086 0.015 FEDFUNDS.l1 0.017 0.013 0.007 intercept 0.001 0.001 0.000 Posterior median of factor loadings: factor1 GDPC1 0 CPIAUCSL 0 FEDFUNDS 0 Posterior interquartile range of factor loadings: factor1 GDPC1 0.001 CPIAUCSL 0.000 FEDFUNDS 0.000 > > > > cleanEx() > nameEx("print.summary.bayesianVARs_predict") > ### * print.summary.bayesianVARs_predict > > flush(stderr()); flush(stdout()) > > ### Name: print.summary.bayesianVARs_predict > ### Title: Print method for summary.bayesianVARs_predict objects > ### Aliases: print.summary.bayesianVARs_predict > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Split data in train and test > train <- data[1:(nrow(data)-4),] > test <- data[-c(1:(nrow(data)-4)),] > > # Estimate model using train data only > mod <- bvar(train, quiet = TRUE) > > # Simulate from 1-step ahead posterior predictive > predictions <- predict(mod, ahead = 1L) 'stable=TRUE': Calling 'stable_bvar()' to discard those posterior draws that do not fulfill the stable criterion. 548/1000 stable posterior draws remaining for prediction! > sum <- summary(predictions) > print(sum) Prediction quantiles: , , GDPC1 t+1 5% -0.07013 50% -0.01913 95% 0.03074 , , CPIAUCSL t+1 5% -0.019531 50% -0.007738 95% 0.003838 , , FEDFUNDS t+1 5% -0.020123 50% -0.003723 95% 0.013727 > > > > > cleanEx() > nameEx("residuals.bayesianVARs_bvar") > ### * residuals.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: residuals.bayesianVARs_bvar > ### Title: Extract Model Residuals > ### Aliases: residuals.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > mod.resids <- residuals(mod) > plot(mod.resids) > > > > cleanEx() > nameEx("specify_prior_phi") > ### * specify_prior_phi > > flush(stderr()); flush(stdout()) > > ### Name: specify_prior_phi > ### Title: Specify prior on PHI > ### Aliases: specify_prior_phi > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Horseshoe prior for a VAR(2) > phi_hs <- specify_prior_phi(data = data, lags = 2L ,prior = "HS") > > # Semi-global-local Horseshoe prior for a VAR(2) with semi-global shrinkage parameters for > # cross-lag and own-lag coefficients in each lag > phi_hs_sg <- specify_prior_phi(data = data, lags = 2L, prior = "HS", + global_grouping = "olcl-lagwise") > > # Semi-global-local Horseshoe prior for a VAR(2) with equation-wise shrinkage > # construct indicator matrix for equation-wise shrinkage > semi_global_mat <- matrix(1:ncol(data), 2*ncol(data), ncol(data), + byrow = TRUE) > phi_hs_ew <- specify_prior_phi(data = data, lags = 2L, prior = "HS", + global_grouping = semi_global_mat) > # (for equation-wise shrinkage one can also use 'global_grouping = "equation-wise"') > > > > > cleanEx() > nameEx("specify_prior_sigma") > ### * specify_prior_sigma > > flush(stderr()); flush(stdout()) > > ### Name: specify_prior_sigma > ### Title: Specify prior on Sigma > ### Aliases: specify_prior_sigma > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # examples with stochastic volatility (heteroscedasticity) ----------------- > # factor-decomposition with 2 factors and colwise normal-gamma prior on the loadings > sigma_factor_cng_sv <- specify_prior_sigma(data = data, type = "factor", + factor_factors = 2L, factor_priorfacloadtype = "colwiseng", factor_heteroskedastic = TRUE) Since argument 'type' is specified with 'factor', all arguments starting with 'cholesky_' are being ignored. > > # cholesky-decomposition with Dirichlet-Laplace prior on U > sigma_cholesky_dl_sv <- specify_prior_sigma(data = data, type = "cholesky", + cholesky_U_prior = "DL", cholesky_DL_a = 0.5, cholesky_heteroscedastic = TRUE) Since argument 'type' is specified with 'cholesky', all arguments starting with 'factor_' are being ignored. > > # examples without stochastic volatility (homoscedasticity) ---------------- > # factor-decomposition with 2 factors and colwise normal-gamma prior on the loadings > sigma_factor_cng <- specify_prior_sigma(data = data, type = "factor", + factor_factors = 2L, factor_priorfacloadtype = "colwiseng", + factor_heteroskedastic = FALSE, factor_priorhomoskedastic = matrix(c(0.5,0.5), + ncol(data), 2)) Since argument 'type' is specified with 'factor', all arguments starting with 'cholesky_' are being ignored. Cannot do deep factor_interweaving if (some) factor_factors are homoskedastic. Setting 'factor_interweaving' to 3. > > # cholesky-decomposition with Horseshoe prior on U > sigma_cholesky_dl <- specify_prior_sigma(data = data, type = "cholesky", + cholesky_U_prior = "HS", cholesky_heteroscedastic = FALSE) Since argument 'type' is specified with 'cholesky', all arguments starting with 'factor_' are being ignored. Argument 'cholesky_priorhomoscedastic' not specified. Setting both shape and rate of inverse gamma prior equal to 0.01. > > > > > cleanEx() > nameEx("specify_structural_restrictions") > ### * specify_structural_restrictions > > flush(stderr()); flush(stdout()) > > ### Name: specify_structural_restrictions > ### Title: Set identifying restrictions for the structural VAR parameters. > ### Aliases: specify_structural_restrictions > > ### ** Examples > > train_data <- 100 * usmacro_growth[,c("GDPC1", "GDPCTPI", "GS1", "M2REAL", "CPIAUCSL")] > prior_sigma <- specify_prior_sigma(train_data, type="cholesky", cholesky_heteroscedastic=FALSE) Since argument 'type' is specified with 'cholesky', all arguments starting with 'factor_' are being ignored. Argument 'cholesky_priorhomoscedastic' not specified. Setting both shape and rate of inverse gamma prior equal to 0.01. > mod <- bvar(train_data, lags=5L, prior_sigma=prior_sigma, quiet=TRUE) > > structural_restrictions <- specify_structural_restrictions( + mod, + restrictions_B0=rbind( + c(1 ,NA,0 ,NA,NA), + c(0 ,1 ,0 ,NA,NA), + c(0 ,NA,1 ,NA,NA), + c(0 ,0 ,NA,1 ,NA), + c(0 ,0 ,0 ,0 ,1 ) + ) + ) > irf_structural <- irf( + mod, ahead=8, + structural_restrictions=structural_restrictions + ) > plot(irf_structural) > > > > > cleanEx() > nameEx("stable_bvar") > ### * stable_bvar > > flush(stderr()); flush(stdout()) > > ### Name: stable_bvar > ### Title: Stable posterior draws > ### Aliases: stable_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Discard "unstable" draws > stable_mod <- stable_bvar(mod) Original 'bayesianVARs_bvar' object consists of 1000 posterior draws. Detected 500 unstable draws. Remaining draws: 500 ! > > > > > cleanEx() > nameEx("sub-.bayesianVARs_coef") > ### * sub-.bayesianVARs_coef > > flush(stderr()); flush(stdout()) > > ### Name: [.bayesianVARs_coef > ### Title: Extract or Replace Parts of a bayesianVARs_coef object > ### Aliases: [.bayesianVARs_coef > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Extract coefficients, which are of class bayesianVARs_coef > phi <- coef(mod) > phi[1,1,1] [1] 0.2228139 attr(,"class") [1] "bayesianVARs_coef" "bayesianVARs_draws" > > > > cleanEx() > nameEx("sub-.bayesianVARs_draws") > ### * sub-.bayesianVARs_draws > > flush(stderr()); flush(stdout()) > > ### Name: [.bayesianVARs_draws > ### Title: Extract or Replace Parts of a bayesianVARs_draws object > ### Aliases: [.bayesianVARs_draws > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Extract coefficients, which are of class bayesianVARs_draws > phi <- coef(mod) > phi[1,1,1] [1] 0.2228139 attr(,"class") [1] "bayesianVARs_coef" "bayesianVARs_draws" > > > > cleanEx() > nameEx("summary.bayesianVARs_bvar") > ### * summary.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: summary.bayesianVARs_bvar > ### Title: Summary method for bayesianVARs_bvar objects > ### Aliases: summary.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Estimate model > mod <- bvar(data, quiet = TRUE) > > # Summary > sum <- summary(mod) > > > > cleanEx() > nameEx("summary.bayesianVARs_draws") > ### * summary.bayesianVARs_draws > > flush(stderr()); flush(stdout()) > > ### Name: summary.bayesianVARs_draws > ### Title: Summary statistics for bayesianVARs posterior draws. > ### Aliases: summary.bayesianVARs_draws > > ### ** Examples > > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Extract posterior draws of VAR coefficients > bvar_coefs <- coef(mod) > > # Compute summary statistics > summary_stats <- summary(bvar_coefs) > > # Compute summary statistics of VAR coefficients without using coef() > summary_stats <- summary(mod$PHI) > > # Test which list elements of 'mod' are of class 'bayesianVARs_draws'. > names(mod)[sapply(names(mod), function(x) inherits(mod[[x]], "bayesianVARs_draws"))] [1] "PHI" "U" "logvar" "sv_para" "facload" "fac" > > > > > cleanEx() > nameEx("summary.bayesianVARs_predict") > ### * summary.bayesianVARs_predict > > flush(stderr()); flush(stdout()) > > ### Name: summary.bayesianVARs_predict > ### Title: Summary method for bayesianVARs_predict objects > ### Aliases: summary.bayesianVARs_predict > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > > # Split data in train and test > train <- data[1:(nrow(data)-4),] > test <- data[-c(1:(nrow(data)-4)),] > > # Estimate model using train data only > mod <- bvar(train, quiet = TRUE) > > # Simulate from 1-step ahead posterior predictive > predictions <- predict(mod, ahead = 1L) 'stable=TRUE': Calling 'stable_bvar()' to discard those posterior draws that do not fulfill the stable criterion. 548/1000 stable posterior draws remaining for prediction! > summary(predictions) Prediction quantiles: , , GDPC1 t+1 5% -0.07013 50% -0.01913 95% 0.03074 , , CPIAUCSL t+1 5% -0.019531 50% -0.007738 95% 0.003838 , , FEDFUNDS t+1 5% -0.020123 50% -0.003723 95% 0.013727 > > > > cleanEx() > nameEx("vcov.bayesianVARs_bvar") > ### * vcov.bayesianVARs_bvar > > flush(stderr()); flush(stdout()) > > ### Name: vcov.bayesianVARs_bvar > ### Title: Extract posterior draws of the (time-varying) > ### variance-covariance matrix for a VAR model > ### Aliases: vcov.bayesianVARs_bvar > > ### ** Examples > > # Access a subset of the usmacro_growth dataset > data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] > # Estimate a model > mod <- bvar(data, sv_keep = "all", quiet = TRUE) > > # Extract posterior draws of the variance-covariance matrix > bvar_vcov <- vcov(mod) > > > > ### *