==3722934== Memcheck, a memory error detector ==3722934== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al. ==3722934== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info ==3722934== Command: /data/blackswan/ripley/R/R-devel-vg/bin/exec/R --vanilla ==3722934== R Under development (unstable) (2026-01-27 r89335) -- "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 + ) ==3722934== Mismatched new/delete size value: 8 ==3722934== at 0x4847B51: operator delete(void*, unsigned long) (/builddir/build/BUILD/valgrind-3.24.0/coregrind/m_replacemalloc/vg_replace_malloc.c:1181) ==3722934== by 0x1DCCE644: operator() (/usr/include/c++/14/bits/unique_ptr.h:93) ==3722934== by 0x1DCCE644: ~unique_ptr (/usr/include/c++/14/bits/unique_ptr.h:398) ==3722934== by 0x1DCCE644: find_rotation_cpp(arma::field > const&, arma::field > const&, std::__cxx11::basic_string, std::allocator > const&, unsigned int, double) (packages/tests-vg/bayesianVARs/src/irf.cpp:459) ==3722934== by 0x1DCA4A12: _bayesianVARs_find_rotation_cpp (packages/tests-vg/bayesianVARs/src/RcppExports.cpp:85) ==3722934== by 0x4A7DCD: R_doDotCall (svn/R-devel/src/main/dotcode.c:766) ==3722934== by 0x4E1E83: bcEval_loop (svn/R-devel/src/main/eval.c:8682) ==3722934== by 0x4F1FD7: bcEval (svn/R-devel/src/main/eval.c:7515) ==3722934== by 0x4F1FD7: bcEval (svn/R-devel/src/main/eval.c:7500) ==3722934== by 0x4F230A: Rf_eval (svn/R-devel/src/main/eval.c:1167) ==3722934== by 0x4F408D: R_execClosure (svn/R-devel/src/main/eval.c:2389) ==3722934== by 0x4F4D46: applyClosure_core (svn/R-devel/src/main/eval.c:2302) ==3722934== by 0x4F2415: Rf_applyClosure (svn/R-devel/src/main/eval.c:2324) ==3722934== by 0x4F2415: Rf_eval (svn/R-devel/src/main/eval.c:1280) ==3722934== by 0x4F70DC: do_set (svn/R-devel/src/main/eval.c:3581) ==3722934== by 0x4F2672: Rf_eval (svn/R-devel/src/main/eval.c:1232) ==3722934== Address 0x17e36070 is 0 bytes inside a block of size 560 alloc'd ==3722934== at 0x4843FEC: operator new(unsigned long) (/builddir/build/BUILD/valgrind-3.24.0/coregrind/m_replacemalloc/vg_replace_malloc.c:487) ==3722934== by 0x1DCCC980: find_rotation_cpp(arma::field > const&, arma::field > const&, std::__cxx11::basic_string, std::allocator > const&, unsigned int, double) (packages/tests-vg/bayesianVARs/src/irf.cpp:374) ==3722934== by 0x1DCA4A12: _bayesianVARs_find_rotation_cpp (packages/tests-vg/bayesianVARs/src/RcppExports.cpp:85) ==3722934== by 0x4A7DCD: R_doDotCall (svn/R-devel/src/main/dotcode.c:766) ==3722934== by 0x4E1E83: bcEval_loop (svn/R-devel/src/main/eval.c:8682) ==3722934== by 0x4F1FD7: bcEval (svn/R-devel/src/main/eval.c:7515) ==3722934== by 0x4F1FD7: bcEval (svn/R-devel/src/main/eval.c:7500) ==3722934== by 0x4F230A: Rf_eval (svn/R-devel/src/main/eval.c:1167) ==3722934== by 0x4F408D: R_execClosure (svn/R-devel/src/main/eval.c:2389) ==3722934== by 0x4F4D46: applyClosure_core (svn/R-devel/src/main/eval.c:2302) ==3722934== by 0x4F2415: Rf_applyClosure (svn/R-devel/src/main/eval.c:2324) ==3722934== by 0x4F2415: Rf_eval (svn/R-devel/src/main/eval.c:1280) ==3722934== by 0x4F70DC: do_set (svn/R-devel/src/main/eval.c:3581) ==3722934== by 0x4F2672: Rf_eval (svn/R-devel/src/main/eval.c:1232) ==3722934== > > 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) > > > > ### *