# bvhar ## Overview `bvhar` provides functions to analyze and forecast multivariate time series using - VAR - VHAR (Vector HAR) - BVAR (Bayesian VAR) - **BVHAR (Bayesian VHAR)** Basically, the package focuses on the research with forecasting. ## Installation ``` r install.packages("bvhar") ``` ### Development version You can install the development version from [develop branch](https://github.com/ygeunkim/bvhar/tree/develop). ``` r # install.packages("remotes") remotes::install_github("ygeunkim/bvhar@develop") ``` We started to develop a Python version in python directory. - [bvhar for Python](https://bvhar.baeconverse.org/python/) - [Source code](https://github.com/ygeunkim/bvhar/tree/master/python) ## Models ``` r library(bvhar) # this package library(dplyr) ``` Repeatedly, `bvhar` is a research tool to analyze multivariate time series model above | Model | function | prior | |:--:|:--:|:--:| | VAR | [`var_lm()`](reference/var_lm.md) | | | VHAR | [`vhar_lm()`](reference/vhar_lm.md) | | | BVAR | [`bvar_minnesota()`](reference/bvar_minnesota.md) | Minnesota (will move to [`var_bayes()`](reference/var_bayes.md)) | | BVHAR | [`bvhar_minnesota()`](reference/bvhar_minnesota.md) | Minnesota (will move to [`vhar_bayes()`](reference/vhar_bayes.md)) | | BVAR | [`var_bayes()`](reference/var_bayes.md) | SSVS, Horseshoe, Minnesota, NG, DL, GDP | | BVHAR | [`vhar_bayes()`](reference/vhar_bayes.md) | SSVS, Horseshoe, Minnesota, NG, DL, GDP | This readme document shows forecasting procedure briefly. Details about each function are in vignettes and help documents. Details will be updated after the function integration works are done. Until then, we remove Bayesian model sections here. h-step ahead forecasting: ``` r h <- 19 etf_split <- divide_ts(etf_vix, h) # Try ?divide_ts etf_tr <- etf_split$train etf_te <- etf_split$test ``` ### VAR VAR(5): ``` r mod_var <- var_lm(y = etf_tr, p = 5) ``` Forecasting: ``` r forecast_var <- predict(mod_var, h) ``` MSE: ``` r (msevar <- mse(forecast_var, etf_te)) #> GVZCLS OVXCLS VXFXICLS VXEEMCLS VXSLVCLS EVZCLS VXXLECLS VXGDXCLS #> 5.381 14.689 2.838 9.451 10.078 0.654 22.436 9.992 #> VXEWZCLS #> 10.647 ``` ### VHAR ``` r mod_vhar <- vhar_lm(y = etf_tr) ``` MSE: ``` r forecast_vhar <- predict(mod_vhar, h) (msevhar <- mse(forecast_vhar, etf_te)) #> GVZCLS OVXCLS VXFXICLS VXEEMCLS VXSLVCLS EVZCLS VXXLECLS VXGDXCLS #> 6.15 2.49 1.52 1.58 10.55 1.35 8.79 4.43 #> VXEWZCLS #> 3.84 ``` ### BVAR ### BVHAR ## Citation Please cite this package with following BibTeX: ``` R @Manual{, title = {{bvhar}: Bayesian Vector Heterogeneous Autoregressive Modeling}, author = {Young Geun Kim and Changryong Baek}, year = {2023}, doi = {10.32614/CRAN.package.bvhar}, note = {R package version 2.4.1}, url = {https://cran.r-project.org/package=bvhar}, } @Article{, title = {Bayesian Vector Heterogeneous Autoregressive Modeling}, author = {Young Geun Kim and Changryong Baek}, journal = {Journal of Statistical Computation and Simulation}, year = {2024}, volume = {94}, number = {6}, pages = {1139--1157}, doi = {10.1080/00949655.2023.2281644}, } ``` ## Code of Conduct Please note that the bvhar project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. # Package index ## Package The bvhar package - [`bvhar`](bvhar-package.md) [`bvhar-package`](bvhar-package.md) : bvhar: Bayesian Vector Heterogeneous Autoregressive Modeling ## Frequentist modeling Vector autoregressive (VAR) and heterogeneous autoregressive (VHAR) models. - [`var_lm()`](var_lm.md) [`print(`*``*`)`](var_lm.md) [`logLik(`*``*`)`](var_lm.md) [`AIC(`*``*`)`](var_lm.md) [`BIC(`*``*`)`](var_lm.md) [`is.varlse()`](var_lm.md) [`is.bvharmod()`](var_lm.md) [`knit_print(`*``*`)`](var_lm.md) : Fitting Vector Autoregressive Model of Order p Model - [`vhar_lm()`](vhar_lm.md) [`print(`*``*`)`](vhar_lm.md) [`logLik(`*``*`)`](vhar_lm.md) [`AIC(`*``*`)`](vhar_lm.md) [`BIC(`*``*`)`](vhar_lm.md) [`is.vharlse()`](vhar_lm.md) [`knit_print(`*``*`)`](vhar_lm.md) : Fitting Vector Heterogeneous Autoregressive Model - [`VARtoVMA()`](VARtoVMA.md) : Convert VAR to VMA(infinite) - [`VHARtoVMA()`](VHARtoVMA.md) : Convert VHAR to VMA(infinite) - [`summary(`*``*`)`](summary.varlse.md) [`print(`*``*`)`](summary.varlse.md) [`knit_print(`*``*`)`](summary.varlse.md) : Summarizing Vector Autoregressive Model - [`summary(`*``*`)`](summary.vharlse.md) [`print(`*``*`)`](summary.vharlse.md) [`knit_print(`*``*`)`](summary.vharlse.md) : Summarizing Vector HAR Model ## Prior specification Prior settings for Bayesian models. - [`set_bvar()`](set_bvar.md) [`set_bvar_flat()`](set_bvar.md) [`set_bvhar()`](set_bvar.md) [`set_weight_bvhar()`](set_bvar.md) [`print(`*``*`)`](set_bvar.md) [`is.bvharspec()`](set_bvar.md) [`knit_print(`*``*`)`](set_bvar.md) : Hyperparameters for Bayesian Models - [`set_ssvs()`](set_ssvs.md) [`print(`*``*`)`](set_ssvs.md) [`is.ssvsinput()`](set_ssvs.md) [`knit_print(`*``*`)`](set_ssvs.md) : Stochastic Search Variable Selection (SSVS) Hyperparameter for Coefficients Matrix and Cholesky Factor - [`set_lambda()`](set_lambda.md) [`set_psi()`](set_lambda.md) [`print(`*``*`)`](set_lambda.md) [`is.bvharpriorspec()`](set_lambda.md) [`knit_print(`*``*`)`](set_lambda.md) : Hyperpriors for Bayesian Models - [`set_horseshoe()`](set_horseshoe.md) [`print(`*``*`)`](set_horseshoe.md) [`is.horseshoespec()`](set_horseshoe.md) [`knit_print(`*``*`)`](set_horseshoe.md) : Horseshoe Prior Specification - [`set_ng()`](set_ng.md) [`print(`*``*`)`](set_ng.md) [`is.ngspec()`](set_ng.md) **\[experimental\]** : Normal-Gamma Hyperparameter for Coefficients and Contemporaneous Coefficients - [`set_dl()`](set_dl.md) [`print(`*``*`)`](set_dl.md) [`is.dlspec()`](set_dl.md) **\[experimental\]** : Dirichlet-Laplace Hyperparameter for Coefficients and Contemporaneous Coefficients - [`set_gdp()`](set_gdp.md) [`is.gdpspec()`](set_gdp.md) **\[experimental\]** : Generalized Double Pareto Shrinkage Hyperparameters for Coefficients and Contemporaneous Coefficients - [`set_ldlt()`](set_ldlt.md) [`set_sv()`](set_ldlt.md) [`print(`*``*`)`](set_ldlt.md) [`is.covspec()`](set_ldlt.md) [`is.svspec()`](set_ldlt.md) [`is.ldltspec()`](set_ldlt.md) **\[experimental\]** : Covariance Matrix Prior Specification - [`set_factor()`](set_factor.md) **\[experimental\]** : Factor Specification - [`set_intercept()`](set_intercept.md) [`print(`*``*`)`](set_intercept.md) [`is.interceptspec()`](set_intercept.md) [`knit_print(`*``*`)`](set_intercept.md) : Prior for Constant Term ## Bayesian modeling Bayesian VAR and Bayesian VHAR models. - [`var_bayes()`](var_bayes.md) [`print(`*``*`)`](var_bayes.md) [`print(`*``*`)`](var_bayes.md) [`knit_print(`*``*`)`](var_bayes.md) [`knit_print(`*``*`)`](var_bayes.md) **\[maturing\]** : Fitting Bayesian VAR with Coefficient and Covariance Prior - [`bvar_minnesota()`](bvar_minnesota.md) [`print(`*``*`)`](bvar_minnesota.md) [`print(`*``*`)`](bvar_minnesota.md) [`logLik(`*``*`)`](bvar_minnesota.md) [`AIC(`*``*`)`](bvar_minnesota.md) [`BIC(`*``*`)`](bvar_minnesota.md) [`is.bvarmn()`](bvar_minnesota.md) [`knit_print(`*``*`)`](bvar_minnesota.md) [`knit_print(`*``*`)`](bvar_minnesota.md) : Fitting Bayesian VAR(p) of Minnesota Prior - [`bvar_flat()`](bvar_flat.md) [`print(`*``*`)`](bvar_flat.md) [`logLik(`*``*`)`](bvar_flat.md) [`AIC(`*``*`)`](bvar_flat.md) [`BIC(`*``*`)`](bvar_flat.md) [`is.bvarflat()`](bvar_flat.md) [`knit_print(`*``*`)`](bvar_flat.md) : Fitting Bayesian VAR(p) of Flat Prior - [`vhar_bayes()`](vhar_bayes.md) [`print(`*``*`)`](vhar_bayes.md) [`print(`*``*`)`](vhar_bayes.md) [`knit_print(`*``*`)`](vhar_bayes.md) [`knit_print(`*``*`)`](vhar_bayes.md) **\[maturing\]** : Fitting Bayesian VHAR with Coefficient and Covariance Prior - [`bvhar_minnesota()`](bvhar_minnesota.md) [`print(`*``*`)`](bvhar_minnesota.md) [`print(`*``*`)`](bvhar_minnesota.md) [`logLik(`*``*`)`](bvhar_minnesota.md) [`AIC(`*``*`)`](bvhar_minnesota.md) [`BIC(`*``*`)`](bvhar_minnesota.md) [`is.bvharmn()`](bvhar_minnesota.md) [`knit_print(`*``*`)`](bvhar_minnesota.md) [`knit_print(`*``*`)`](bvhar_minnesota.md) : Fitting Bayesian VHAR of Minnesota Prior - [`summary(`*``*`)`](summary.normaliw.md) [`print(`*``*`)`](summary.normaliw.md) [`knit_print(`*``*`)`](summary.normaliw.md) : Summarizing Bayesian Multivariate Time Series Model - [`print(`*``*`)`](summary.bvharsp.md) [`knit_print(`*``*`)`](summary.bvharsp.md) [`summary(`*``*`)`](summary.bvharsp.md) [`summary(`*``*`)`](summary.bvharsp.md) [`summary(`*``*`)`](summary.bvharsp.md) : Summarizing BVAR and BVHAR with Shrinkage Priors ## Deprecated Deprecated functions that will be removed soon - [`choose_bvar()`](choose_bvar.md) [`choose_bvhar()`](choose_bvar.md) [`print(`*``*`)`](choose_bvar.md) [`is.bvharemp()`](choose_bvar.md) [`knit_print(`*``*`)`](choose_bvar.md) **\[deprecated\]** : Finding the Set of Hyperparameters of Individual Bayesian Model - [`bound_bvhar()`](bound_bvhar.md) [`print(`*``*`)`](bound_bvhar.md) [`is.boundbvharemp()`](bound_bvhar.md) [`knit_print(`*``*`)`](bound_bvhar.md) **\[deprecated\]** : Setting Empirical Bayes Optimization Bounds - [`choose_bayes()`](choose_bayes.md) **\[deprecated\]** : Finding the Set of Hyperparameters of Bayesian Model ## Forecasting - [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`predict(`*``*`)`](predict.md) [`print(`*``*`)`](predict.md) [`is.predbvhar()`](predict.md) [`knit_print(`*``*`)`](predict.md) : Forecasting Multivariate Time Series - [`divide_ts()`](divide_ts.md) : Split a Time Series Dataset into Train-Test Set - [`forecast_roll()`](forecast_roll.md) [`print(`*``*`)`](forecast_roll.md) [`is.bvharcv()`](forecast_roll.md) [`knit_print(`*``*`)`](forecast_roll.md) : Out-of-sample Forecasting based on Rolling Window - [`forecast_expand()`](forecast_expand.md) : Out-of-sample Forecasting based on Expanding Window ## Structural analysis - [`print(`*``*`)`](irf.md) [`irf()`](irf.md) [`is.bvharirf()`](irf.md) [`knit_print(`*``*`)`](irf.md) : Impulse Response Analysis - [`spillover()`](spillover.md) [`print(`*``*`)`](spillover.md) [`knit_print(`*``*`)`](spillover.md) : h-step ahead Normalized Spillover - [`dynamic_spillover()`](dynamic_spillover.md) [`print(`*``*`)`](dynamic_spillover.md) [`knit_print(`*``*`)`](dynamic_spillover.md) : Dynamic Spillover ## Evaluation - [`mse()`](mse.md) : Evaluate the Model Based on MSE (Mean Square Error) - [`mae()`](mae.md) : Evaluate the Model Based on MAE (Mean Absolute Error) - [`mape()`](mape.md) : Evaluate the Model Based on MAPE (Mean Absolute Percentage Error) - [`mase()`](mase.md) : Evaluate the Model Based on MASE (Mean Absolute Scaled Error) - [`mrae()`](mrae.md) : Evaluate the Model Based on MRAE (Mean Relative Absolute Error) - [`alpl()`](alpl.md) : Evaluate the Density Forecast Based on Average Log Predictive Likelihood (APLP) - [`relmae()`](relmae.md) : Evaluate the Model Based on RelMAE (Relative MAE) - [`rmsfe()`](rmsfe.md) : Evaluate the Model Based on RMSFE - [`rmafe()`](rmafe.md) : Evaluate the Model Based on RMAFE - [`rmape()`](rmape.md) : Evaluate the Model Based on RMAPE (Relative MAPE) - [`rmase()`](rmase.md) : Evaluate the Model Based on RMASE (Relative MASE) - [`conf_fdr()`](conf_fdr.md) : Evaluate the Sparsity Estimation Based on FDR - [`conf_fnr()`](conf_fnr.md) : Evaluate the Sparsity Estimation Based on FNR - [`conf_fscore()`](conf_fscore.md) : Evaluate the Sparsity Estimation Based on F1 Score - [`conf_prec()`](conf_prec.md) : Evaluate the Sparsity Estimation Based on Precision - [`conf_recall()`](conf_recall.md) : Evaluate the Sparsity Estimation Based on Recall - [`confusion()`](confusion.md) : Evaluate the Sparsity Estimation Based on Confusion Matrix - [`fromse()`](fromse.md) : Evaluate the Estimation Based on Frobenius Norm - [`spne()`](spne.md) : Evaluate the Estimation Based on Spectral Norm Error - [`relspne()`](relspne.md) : Evaluate the Estimation Based on Relative Spectral Norm Error - [`compute_logml()`](compute_logml.md) : Extracting Log of Marginal Likelihood - [`FPE()`](FPE.md) : Final Prediction Error Criterion - [`HQ()`](HQ.md) : Hannan-Quinn Criterion - [`choose_var()`](choose_var.md) : Choose the Best VAR based on Information Criteria - [`compute_dic()`](compute_dic.md) : Deviance Information Criterion of Multivariate Time Series Model ## Plots - [`autoplot(`*``*`)`](autoplot.normaliw.md) : Residual Plot for Minnesota Prior VAR Model - [`autoplot(`*``*`)`](autoplot.summary.normaliw.md) : Density Plot for Minnesota Prior VAR Model - [`autoplot(`*``*`)`](autoplot.predbvhar.md) [`autolayer(`*``*`)`](autoplot.predbvhar.md) : Plot Forecast Result - [`geom_eval()`](geom_eval.md) : Adding Test Data Layer - [`gg_loss()`](gg_loss.md) : Compare Lists of Models - [`autoplot(`*``*`)`](autoplot.bvharirf.md) : Plot Impulse Responses - [`autoplot(`*``*`)`](autoplot.bvharsp.md) : Plot the Result of BVAR and BVHAR MCMC - [`autoplot(`*``*`)`](autoplot.summary.bvharsp.md) : Plot the Heatmap of SSVS Coefficients - [`autoplot(`*``*`)`](autoplot.bvhardynsp.md) : Dynamic Spillover Indices Plot ## Simulation and Random Generation - [`sim_var()`](sim_var.md) : Generate Multivariate Time Series Process Following VAR(p) - [`sim_vhar()`](sim_vhar.md) : Generate Multivariate Time Series Process Following VAR(p) - [`sim_mncoef()`](sim_mncoef.md) : Generate Minnesota BVAR Parameters - [`sim_mnvhar_coef()`](sim_mnvhar_coef.md) : Generate Minnesota BVAR Parameters - [`sim_mnormal()`](sim_mnormal.md) : Generate Multivariate Normal Random Vector - [`sim_matgaussian()`](sim_matgaussian.md) : Generate Matrix Normal Random Matrix - [`sim_iw()`](sim_iw.md) : Generate Inverse-Wishart Random Matrix - [`sim_mniw()`](sim_mniw.md) : Generate Normal-IW Random Family - [`sim_mvt()`](sim_mvt.md) : Generate Multivariate t Random Vector ## Data - [`etf_vix`](etf_vix.md) : CBOE ETF Volatility Index Dataset ## Other generic functions - [`stableroot()`](stableroot.md) : Roots of characteristic polynomial - [`is.stable()`](is.stable.md) : Stability of the process - [`coef(`*``*`)`](coef.md) [`coef(`*``*`)`](coef.md) [`coef(`*``*`)`](coef.md) [`coef(`*``*`)`](coef.md) [`coef(`*``*`)`](coef.md) [`coef(`*``*`)`](coef.md) [`coef(`*``*`)`](coef.md) : Coefficient Matrix of Multivariate Time Series Models - [`residuals(`*``*`)`](residuals.md) [`residuals(`*``*`)`](residuals.md) [`residuals(`*``*`)`](residuals.md) [`residuals(`*``*`)`](residuals.md) [`residuals(`*``*`)`](residuals.md) : Residual Matrix from Multivariate Time Series Models - [`fitted(`*``*`)`](fitted.md) [`fitted(`*``*`)`](fitted.md) [`fitted(`*``*`)`](fitted.md) [`fitted(`*``*`)`](fitted.md) [`fitted(`*``*`)`](fitted.md) : Fitted Matrix from Multivariate Time Series Models # Articles ### All vignettes - [Introduction to bvhar](bvhar.md): - [Forecasting](forecasting.md): - [Minnesota Prior](minnesota.md): - [Bayesian VAR and VHAR Models](shrinkage.md): - [Stochastic Volatility Models](stochastic-volatility.md):