diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index ffa3c951..5427534b 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -49,7 +49,7 @@ jobs: shell: Rscript {0} - name: Deploy to GitHub pages 🚀 - if: github.event_name != 'pull_request' && "!startsWith(github.ref, 'refs/heads/release/')" + if: "github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/heads/release/')" uses: JamesIves/github-pages-deploy-action@v4.6.1 with: token: ${{ secrets.YGEUNKIM_PAGE_PAT }} diff --git a/README.Rmd b/README.Rmd index 123089e7..3ce0dc2d 100644 --- a/README.Rmd +++ b/README.Rmd @@ -49,7 +49,7 @@ install.packages("bvhar") [![dev-r-cmd-check](https://github.com/ygeunkim/bvhar/actions/workflows/R-CMD-check.yaml/badge.svg?branch=develop)](https://github.com/ygeunkim/bvhar/actions/workflows/R-CMD-check.yaml?query=branch%3Adevelop) -[![dev-codecov](https://codecov.io/github/ygeunkim/bvhar/branch/develop/graph/badge.svg)](https://codecov.io/github/ygeunkim/bvhar) +[![dev-codecov](https://codecov.io/github/ygeunkim/bvhar/branch/develop/graph/badge.svg)](https://app.codecov.io/gh/ygeunkim/bvhar/tree/develop) [![Development version updated](https://img.shields.io/github/last-commit/ygeunkim/bvhar/develop?label=dev%20updated)](https://github.com/ygeunkim/bvhar/tree/develop) @@ -60,6 +60,11 @@ You can install the development version from [develop branch](https://github.com remotes::install_github("ygeunkim/bvhar@develop") ``` +We started to develop a Python version in python directory. + +- [bvhar for Python](https://ygeunkim.github.io/package/bvhar/python/) +- [Source code](https://github.com/ygeunkim/bvhar/tree/develop/python) + ## Models ```{r example, message=FALSE} @@ -80,6 +85,7 @@ Repeatedly, `bvhar` is a research tool to analyze multivariate time series model This readme document shows forecasting procedure briefly. Details about each function are in vignettes and help documents. +Note that each `bvar_minnesota()` and `bvhar_minnesota()` will be integrated into `var_bayes()` and `vhar_bayes()` and removed in the next version. h-step ahead forecasting: @@ -186,16 +192,6 @@ forecast_bvhar_v2 <- predict(mod_bvhar_v2, h) (msebvhar_v2 <- mse(forecast_bvhar_v2, etf_te)) ``` -## Plots - -```{r predfig} -autoplot(forecast_var, x_cut = 870, ci_alpha = .7, type = "wrap") + - autolayer(forecast_vhar, ci_alpha = .6) + - autolayer(forecast_bvar, ci_alpha = .4) + - autolayer(forecast_bvhar_v1, ci_alpha = .2) + - autolayer(forecast_bvhar_v2, ci_alpha = .1) -``` - ## Citation Please cite this package with following BibTeX: diff --git a/README.md b/README.md index 146732bb..e411af16 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ install.packages("bvhar") [![dev-r-cmd-check](https://github.com/ygeunkim/bvhar/actions/workflows/R-CMD-check.yaml/badge.svg?branch=develop)](https://github.com/ygeunkim/bvhar/actions/workflows/R-CMD-check.yaml?query=branch%3Adevelop) -[![dev-codecov](https://codecov.io/github/ygeunkim/bvhar/branch/develop/graph/badge.svg)](https://codecov.io/github/ygeunkim/bvhar) +[![dev-codecov](https://codecov.io/github/ygeunkim/bvhar/branch/develop/graph/badge.svg)](https://app.codecov.io/gh/ygeunkim/bvhar/tree/develop) [![Development version updated](https://img.shields.io/github/last-commit/ygeunkim/bvhar/develop?label=dev%20updated)](https://github.com/ygeunkim/bvhar/tree/develop) @@ -52,6 +52,11 @@ branch](https://github.com/ygeunkim/bvhar/tree/develop). remotes::install_github("ygeunkim/bvhar@develop") ``` +We started to develop a Python version in python directory. + +- [bvhar for Python](https://ygeunkim.github.io/package/bvhar/python/) +- [Source code](https://github.com/ygeunkim/bvhar/tree/develop/python) + ## Models ``` r @@ -72,7 +77,9 @@ series model above | BVHAR | `vhar_bayes()` | SSVS, Horseshoe, Minnesota, NG, DL | This readme document shows forecasting procedure briefly. Details about -each function are in vignettes and help documents. +each function are in vignettes and help documents. Note that each +`bvar_minnesota()` and `bvhar_minnesota()` will be integrated into +`var_bayes()` and `vhar_bayes()` and removed in the next version. h-step ahead forecasting: @@ -274,18 +281,6 @@ forecast_bvhar_v2 <- predict(mod_bvhar_v2, h) #> 5.54 ``` -## Plots - -``` r -autoplot(forecast_var, x_cut = 870, ci_alpha = .7, type = "wrap") + - autolayer(forecast_vhar, ci_alpha = .6) + - autolayer(forecast_bvar, ci_alpha = .4) + - autolayer(forecast_bvhar_v1, ci_alpha = .2) + - autolayer(forecast_bvhar_v2, ci_alpha = .1) -``` - - - ## Citation Please cite this package with following BibTeX: @@ -294,7 +289,8 @@ Please cite this package with following BibTeX: title = {{bvhar}: Bayesian Vector Heterogeneous Autoregressive Modeling}, author = {Young Geun Kim and Changryong Baek}, year = {2023}, - note = {R package version 2.0.1.9014}, + doi = {10.32614/CRAN.package.bvhar}, + note = {R package version 2.1.0}, url = {https://cran.r-project.org/package=bvhar}, } @@ -302,7 +298,10 @@ Please cite this package with following BibTeX: title = {Bayesian Vector Heterogeneous Autoregressive Modeling}, author = {Young Geun Kim and Changryong Baek}, journal = {Journal of Statistical Computation and Simulation}, - year = {2023}, + year = {2024}, + volume = {94}, + number = {6}, + pages = {1139--1157}, doi = {10.1080/00949655.2023.2281644}, } diff --git a/_pkgdown.yml b/_pkgdown.yml index de1bbbb8..72a974af 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -17,7 +17,7 @@ home: # see the configuration in .github/workflows/pkgdown.yaml - text: VERSION_TEXT href: VERSION_REF - - text: bvhar in Python + - text: bvhar for Python href: https://ygeunkim.github.io/package/bvhar/python/ development: @@ -46,7 +46,6 @@ reference: Prior settings for Bayesian models. contents: - set_bvar - - init_ssvs - set_ssvs - set_lambda - set_horseshoe @@ -70,7 +69,7 @@ reference: - title: Deprecated desc: > - Deprecated modeling functions that will be removed soon + Deprecated functions that will be removed soon contents: - bvar_sv - bvar_ssvs @@ -78,6 +77,10 @@ reference: - bvhar_sv - bvhar_ssvs - bvhar_horseshoe + - init_ssvs + - choose_ssvs + - sim_ssvs_var + - sim_horseshoe_var - title: Forecasting desc: ~ @@ -125,7 +128,6 @@ reference: - choose_bvhar - bound_bvhar - choose_bayes - - choose_ssvs - title: Information criteria desc: ~ @@ -161,8 +163,6 @@ reference: - sim_mniw - sim_mvt - sim_gig - - sim_ssvs_var - - sim_horseshoe_var - title: Data desc: ~ @@ -178,13 +178,16 @@ reference: - residuals - fitted -# destination: '../../myprofile/young-blogdown/static/package/bvhar' - navbar: structure: - left: [intro, reference, articles, tutorials, news, research, accepted] + left: [intro, reference, articles, tutorials, news, publication, research, accepted] right: [github, goback] components: + publication: + icon: fa-newspaper + href: https://www.tandfonline.com/eprint/ZIRSC2CDJ9JM9FK2E3WD/full?target=10.1080/00949655.2023.2281644 + aria-label: Published + text: Published research: icon: fa-laptop-code href: https://github.com/ygeunkim/paper-bvhar @@ -204,15 +207,17 @@ news: href: https://github.com/ygeunkim/bvhar/releases/tag/v0.12.0 # - text: "Version 1.0.0" # href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.0 - # - text: "Version 1.0.1" - # href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.1 - # - text: "Version 1.0.2" - # href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.2 - # - text: "Version 1.1.0" - # href: https://github.com/ygeunkim/bvhar/releases/tag/v1.1.0 + - text: "Version 1.0.1" + href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.1 + - text: "Version 1.0.2" + href: https://github.com/ygeunkim/bvhar/releases/tag/v1.0.2 + - text: "Version 1.1.0" + href: https://github.com/ygeunkim/bvhar/releases/tag/v1.1.0 - text: "Version 1.2.0" href: https://github.com/ygeunkim/bvhar/releases/tag/v1.2.0 - # - text: "Version 2.0.0" - # href: https://github.com/ygeunkim/bvhar/releases/tag/v2.0.0 + - text: "Version 2.0.0" + href: https://github.com/ygeunkim/bvhar/releases/tag/v2.0.0 - text: "Version 2.0.1" href: https://github.com/ygeunkim/bvhar/releases/tag/v2.0.1 + - text: "Version 2.1.0" + href: https://github.com/ygeunkim/bvhar/releases/tag/v2.1.0 diff --git a/man/figures/README-predfig-1.png b/man/figures/README-predfig-1.png deleted file mode 100644 index 00c1d128..00000000 Binary files a/man/figures/README-predfig-1.png and /dev/null differ diff --git a/revdep/README.md b/revdep/README.md index e807306a..0c9d9188 100644 --- a/revdep/README.md +++ b/revdep/README.md @@ -1,23 +1,41 @@ # Platform -|field |value | -|:--------|:---------------------------------------------| -|version |R version 4.3.2 (2023-10-31) | -|os |macOS Ventura 13.6.4 | -|system |aarch64, darwin20 | -|ui |X11 | -|language |(EN) | -|collate |en_US.UTF-8 | -|ctype |UTF-8 | -|tz |Asia/Seoul | -|date |2024-03-01 | -|pandoc |3.1.12.1 @ /opt/homebrew/bin/ (via rmarkdown) | +|field |value | +|:--------|:----------------------------| +|version |R version 4.3.3 (2024-02-29) | +|os |macOS Big Sur ... 10.16 | +|system |x86_64, darwin20 | +|ui |X11 | +|language |(EN) | +|collate |en_US.UTF-8 | +|ctype |en_US.UTF-8 | +|tz |Asia/Seoul | +|date |2024-09-16 | +|pandoc |3.3 @ /usr/local/bin/pandoc | # Dependencies -|package |old |new |Δ | -|:-------|:-----|:-----|:--| -|bvhar |2.0.0 |2.0.1 |* | +|package |old |new |Δ | +|:-----------|:-----|:---------|:--| +|bvhar |2.0.1 |2.1.0 |* | +|abind |NA |1.4-8 |* | +|backports |NA |1.5.0 |* | +|checkmate |NA |2.3.2 |* | +|cli |NA |3.6.3 |* | +|colorspace |NA |2.1-1 |* | +|cpp11 |NA |0.4.7 |* | +|farver |NA |2.1.2 |* | +|ggplot2 |NA |3.5.1 |* | +|gtable |NA |0.3.5 |* | +|matrixStats |NA |1.4.1 |* | +|munsell |NA |0.5.1 |* | +|posterior |NA |1.5.0 |* | +|Rcpp |NA |1.0.13 |* | +|RcppEigen |NA |0.3.4.0.2 |* | +|rlang |NA |1.1.4 |* | +|stringi |NA |1.8.4 |* | +|tidyselect |NA |1.2.1 |* | +|withr |NA |3.0.1 |* | # Revdeps diff --git a/vignettes/bvhar.Rmd b/vignettes/bvhar.Rmd index deeaeb99..5f286f84 100644 --- a/vignettes/bvhar.Rmd +++ b/vignettes/bvhar.Rmd @@ -238,7 +238,8 @@ names(fit_har) ## BVAR -`bvhar` package provides two prior framework - Minnesota prior and flat prior. +This page provides deprecated two functions examples. +Both `bvar_minnesota()` and `bvar_flat()` will be integrated into `var_bayes()` and removed in the next version. ### Minnesota prior @@ -348,6 +349,7 @@ We call this VAR-type Minnesota prior or BVHAR-S. `bvhar_minnesota(y, har = c(5, 22), bayes_spec, include_mean = TRUE)` can fit BVHAR with this prior. This is the default prior setting. +Similar to above functions, this function will be also integrated into `vhar_bayes()` and removed in the next version. ```{r} (fit_bvhar_v1 <- bvhar_minnesota(etf_train, num_iter = 10, bayes_spec = bvhar_spec_v1)) diff --git a/vignettes/shrinkage.Rmd b/vignettes/shrinkage.Rmd index f0e032ef..d1db232e 100644 --- a/vignettes/shrinkage.Rmd +++ b/vignettes/shrinkage.Rmd @@ -1,8 +1,8 @@ --- -title: "Shrinkage Priors" +title: "Bayesian VAR and VHAR Models" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{Shrinkage Priors} + %\VignetteIndexEntry{Bayesian VAR and VHAR Models} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -26,7 +26,7 @@ library(bvhar) ``` ```{r etfdat} -etf <- etf_vix[1:100, 1:3] +etf <- etf_vix[1:55, 1:3] # Split------------------------------- h <- 5 etf_eval <- divide_ts(etf, h) @@ -34,28 +34,36 @@ etf_train <- etf_eval$train etf_test <- etf_eval$test ``` +# Bayesian VAR and VHAR -# Stochastic Search Variable Selection (SSVS) Prior +`var_bayes()` and `vhar_bayes()` fit BVAR and BVHAR each with various priors. - `y`: Multivariate time series data. It should be data frame or matrix, which means that every column is numeric. Each column indicates variable, i.e. it sould be wide format. -- `har`: Order of VHAR +- `p` or `har`: VAR lag, or order of VHAR - `num_chains`: Number of chains - If OpenMP is enabled, parallel loop will be run. - `num_iter`: Total number of iterations - `num_burn`: Number of burn-in - `thinning`: Thinning - `bayes_spec`: Output of `set_ssvs()` - - By default, use a default semi-automatic approach using `choose_ssvs()`. - - + - Minneosta prior + - BVAR: `set_bvar()` + - BVHAR: `set_bvhar()` and `set_weight_bvhar()` + - Can induce prior on $\lambda$ using `lambda = set_lambda()` + - SSVS prior: `set_ssvs()` + - Horseshoe prior: `set_horseshoe()` + - NG prior: `set_ng()` + - DL prior: `set_dl()` - `cov_spec`: Covariance prior specification. Use `set_ldlt()` for homoskedastic model. - `include_mean = TRUE`: By default, you include the constant term in the model. - `minnesota = c("no", "short", "longrun")`: Minnesota-type shrinkage. - `verbose = FALSE`: Progress bar - `num_thread`: Number of thread for OpenMP - - Used in both Eigen computation and parallel multi-chain loop + - Used in parallel multi-chain loop - This option is valid only when OpenMP in user's machine. +## Stochastic Search Variable Selection (SSVS) Prior + ```{r fitssvs} (fit_ssvs <- vhar_bayes(etf_train, num_chains = 1, num_iter = 20, bayes_spec = set_ssvs(), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun")) ``` @@ -68,7 +76,7 @@ autoplot(fit_ssvs) ``` -# Horseshoe Prior +## Horseshoe Prior `bayes_spec` is the initial specification by `set_horseshoe()`. Others are the same. @@ -80,6 +88,23 @@ autoplot(fit_ssvs) autoplot(fit_hs) ``` +## Minnesota Prior + +```{r fitmn} +(fit_mn <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, bayes_spec = set_bvhar(lambda = set_lambda()), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun")) +``` + +## Normal-Gamma prior + +```{r fitng} +(fit_ng <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, bayes_spec = set_ng(), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun")) +``` + +## Dirichlet-Laplace prior + +```{r fitdl} +(fit_dl <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, bayes_spec = set_dl(), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun")) +``` # Bayesian visualization diff --git a/vignettes/stochastic-volatility.Rmd b/vignettes/stochastic-volatility.Rmd index 6e5ff40c..5769cba3 100644 --- a/vignettes/stochastic-volatility.Rmd +++ b/vignettes/stochastic-volatility.Rmd @@ -26,7 +26,7 @@ library(bvhar) ``` ```{r etfdat} -etf <- etf_vix[1:100, 1:3] +etf <- etf_vix[1:55, 1:3] # Split------------------------------- h <- 5 etf_eval <- divide_ts(etf, h) @@ -45,6 +45,8 @@ By specifying `cov_spec = set_sv()`, - BVHAR: `set_bvhar()` and `set_weight_bvhar()` - SSVS prior: `set_ssvs()` - Horseshoe prior: `set_horseshoe()` + - NG prior: `set_ng()` + - DL prior: `set_dl()` - `sv_spec`: prior settings for SV, `set_sv()` - `intercept`: prior for constant term, `set_intercept()` @@ -52,25 +54,30 @@ By specifying `cov_spec = set_sv()`, set_sv() ``` -```{r setinter} -set_intercept() -``` - ## SSVS ```{r svssvs} -(fit_ssvs <- vhar_bayes(etf_train, num_chains = 2, num_iter = 50, bayes_spec = set_ssvs(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")) +(fit_ssvs <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, bayes_spec = set_ssvs(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")) ``` -```{r heatssvssv} -autoplot(fit_ssvs) -``` ## Horseshoe -```{r} -(fit_hs <- vhar_bayes(etf_train, num_chains = 2, num_iter = 50, bayes_spec = set_horseshoe(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")) +```{r hssv} +(fit_hs <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, bayes_spec = set_horseshoe(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")) +``` + +## Normal-Gamma prior + +```{r ngsv} +(fit_ng <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, bayes_spec = set_ng(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")) +``` + +## Dirichlet-Laplace prior + +```{r dlsv} +(fit_dl <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, bayes_spec = set_dl(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")) ``` ## Bayesian visualization