View source: R/mcmc_samplers.R
tvar | R Documentation |
Run the MCMC for a time-varying autoregression with a penalty on first (D=1) or second (D=2) differences of each dynamic autoregressive coefficient. The penalty is determined by the prior on the evolution errors, which include:
the dynamic horseshoe prior ('DHS');
the static horseshoe prior ('HS');
the Bayesian lasso ('BL');
the normal stochastic volatility model ('SV');
the normal-inverse-gamma prior ('NIG').
In each case, the evolution error is a scale mixture of Gaussians. Sampling is accomplished with a (parameter-expanded) Gibbs sampler, mostly relying on a dynamic linear model representation.
tvar(
y,
p_max = 1,
include_intercept = FALSE,
evol_error = "DHS",
D = 2,
useObsSV = FALSE,
nsave = 1000,
nburn = 1000,
nskip = 4,
mcmc_params = list("mu", "yhat", "beta", "evol_sigma_t2", "obs_sigma_t2", "dhs_phi",
"dhs_mean"),
computeDIC = TRUE,
verbose = TRUE
)
y |
the |
p_max |
the maximum order of lag to include |
include_intercept |
logical; if TRUE, include a time-varying intercept |
evol_error |
the evolution error distribution; must be one of 'DHS' (dynamic horseshoe prior), 'HS' (horseshoe prior), 'BL' (Bayesian lasso), or 'NIG' (normal-inverse-gamma prior) |
D |
degree of differencing (D = 1 or D = 2) |
useObsSV |
logical; if TRUE, include a (normal) stochastic volatility model for the observation error variance |
nsave |
number of MCMC iterations to record |
nburn |
number of MCMC iterations to discard (burin-in) |
nskip |
number of MCMC iterations to skip between saving iterations, i.e., save every (nskip + 1)th draw |
mcmc_params |
named list of parameters for which we store the MCMC output; must be one or more of:
|
computeDIC |
logical; if TRUE, compute the deviance information criterion |
verbose |
logical; should R report extra information on progress? |
A named list of the nsave
MCMC samples for the parameters named in mcmc_params
The data y
may NOT contain NAs. The data y
will be used to construct
the predictor matrix (of lagged values), which is not permitted to include NAs.
## Not run:
# Example 1:
simdata = simUnivariate(signalName = "doppler", T = 128, RSNR = 7, include_plot = TRUE)
y = simdata$y
# Note: in general should subtract off the sample mean
p = 6 # Lag
out = tvar(y, p_max = p, include_intercept = FALSE,
evol_error = 'DHS', D = 1,
mcmc_params = list('mu', 'yhat', 'beta', 'obs_sigma_t2'))
for(j in 1:p)
plot_fitted(rep(0, length(y) - p),
mu = colMeans(out$beta[,,j]),
postY = out$beta[,,j])
plot_fitted(y[-(1:p)],
mu = colMeans(out$mu),
postY = out$yhat,
y_true = simdata$y_true[-(1:p)])
spec_TF = post_spec_dsp(post_ar_coefs = out$beta,
post_sigma_e = sqrt(out$obs_sigma_t2[,1]),
n.freq = 100)
image(x = 1:(length(y)-p), y = spec_TF$freq, colMeans(log(spec_TF$post_spec)),
xlab = 'Time', ylab = 'Freqency', main = 'Posterior Mean of Log-Spectrum')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.