knitr::opts_chunk$set( comment = "#>", collapse = TRUE, out.width = "70%", fig.align = "center", fig.width = 6, fig.asp = .618 ) orig_opts <- options("digits") options(digits = 3) set.seed(1)
library(bvhar)
etf <- etf_vix[1:55, 1:3] # Split------------------------------- h <- 5 etf_eval <- divide_ts(etf, h) etf_train <- etf_eval$train etf_test <- etf_eval$test
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.p or har: VAR lag, or order of VHARnum_chains: Number of chainsnum_iter: Total number of iterationsnum_burn: Number of burn-inthinning: Thinningcoef_spec: Coefficient prior specification.set_bvar()set_bvhar() and set_weight_bvhar()lambda = set_lambda()set_ssvs()set_horseshoe()set_ng()set_dl()contem_spec: Contemporaneous prior specification.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 barnum_thread: Number of thread for OpenMP(fit_ssvs <- vhar_bayes(etf_train, num_chains = 1, num_iter = 20, coef_spec = set_ssvs(), contem_spec = set_ssvs(), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun"))
autoplot() for the fit (bvharsp object) provides coefficients heatmap.
There is type argument, and the default type = "coef" draws the heatmap.
autoplot(fit_ssvs)
coef_spec is the initial specification by set_horseshoe(). Others are the same.
(fit_hs <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_horseshoe(), contem_spec = set_horseshoe(), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun"))
autoplot(fit_hs)
(fit_mn <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_bvhar(lambda = set_lambda()), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun"))
(fit_ng <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_ng(), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun"))
(fit_dl <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_dl(), cov_spec = set_ldlt(), include_mean = FALSE, minnesota = "longrun"))
autoplot() also provides Bayesian visualization. type = "trace" gives MCMC trace plot.
autoplot(fit_hs, type = "trace", regex_pars = "tau")
type = "dens" draws MCMC density plot. If specifying additional argument facet_args = list(dir = "v") of bayesplot, you can see plot as the same format with coefficient matrix.
autoplot(fit_hs, type = "dens", regex_pars = "kappa", facet_args = list(dir = "v", nrow = nrow(fit_hs$coefficients)))
options(orig_opts)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.