Learn R Programming

shrinkTVP (version 1.0.0)

shrinkTVP: Markov Chain Monte Carlo (MCMC) for time-varying parameter models with shrinkage

Description

shrinkTVP samples from the joint posterior distribution of the parameters of a time-varying parameter model with shrinkage, potentially including stochastiv volatility (SV), and returns the MCMC draws.

Usage

shrinkTVP(formula, data, niter = 10000, nburn = round(niter/2),
  nthin = 1, learn_a_xi = TRUE, learn_a_tau = TRUE, a_xi = 0.1,
  a_tau = 0.1, learn_kappa2 = TRUE, learn_lambda2 = TRUE,
  kappa2 = 20, lambda2 = 20, hyperprior_param, c_tuning_par_xi = 1,
  c_tuning_par_tau = 1, display_progress = TRUE, ret_beta_nc = FALSE,
  sv = FALSE, sv_param, LPDS = FALSE, y_test, x_test)

Arguments

formula

an object of class "formula": a symbolic representation of the model, as in the function lm. For details, see formula.

data

optional data frame containing the response variable and the covariates. If not found in data, the variables are taken from environment(formula), typically the environment from which shrinkTVP is called. No NAs are allowed in the response variable and the covariates.

niter

positive integer, indicating the number of MCMC iterations to perform, including the burn-in. Has to be larger than or equal to nburn + 2. The default value is 10000.

nburn

non-negative integer, indicating the number of iterations discarded as burn-in. Has to be smaller than or equal to niter - 2. The default value is round(niter / 2).

nthin

positive integer, indicating the degree of thinning to be performed. Every nthin draw is kept and returned. The default value is 1, implying that every draw is kept.

learn_a_xi

logical value indicating whether to learn a_xi, the local adaptation parameter of the state variances. The default value is TRUE.

learn_a_tau

logical value indicating whether to learn a_tau, the local adaptation parameter of the mean of the initial values of the states. The default value is TRUE.

a_xi

positive, real number, indicating the (fixed) value for a_xi. Ignored if learn_a_xi is TRUE. The default value is 0.1.

a_tau

positive, real number, indicating the (fixed) value for a_tau. Ignored if learn_a_tau is TRUE. The default value is 0.1.

learn_kappa2

logical value indicating whether to learn kappa2, the global level of shrinkage for the state variances. The default value is TRUE.

learn_lambda2

logical value indicating whether to learn the lambda^2 parameter, the global level of shrinkage for the mean of the initial values of the states. The default value is TRUE.

kappa2

positive, real number, indicating the (fixed) value for kappa2. Ignored if learn_kappa2 is TRUE. The default value is 20.

lambda2

positive, real number, indicating the (fixed) value for lambda2. Ignored if learn_lambda2 is TRUE. The default value is 20.

hyperprior_param

optional named list containing hyperparameter values. Not all have to be supplied, with those missing being replaced by the default values. Any list elements that are misnamed will be ignored and a warning will be thrown. All hyperparameter values have to be positive, real numbers. The following hyperparameters can be supplied:

  • c0: The default value is 2.5.

  • g0: The default value is 5.

  • G0: The default value is 5 / (2.5 - 1).

  • cp: The default value is 1.

  • np: The default value is 20.

  • e1: The default value is 0.001.

  • e2: The default value is 0.001.

  • d1: The default value is 0.001.

  • d2: The default value is 0.001.

  • b_xi: The default value is 10.

  • b_tau: The default value is 10.

  • nu_xi: The default value is 5.

  • nu_tau: The default value is 5.

c_tuning_par_xi

positive, real number. Determines the standard deviation of the proposal distribution for the Metropolis Hastings step for a_xi. Ignored if learn_a_xi is FALSE. The default value is 1.

c_tuning_par_tau

positive, real number. Determines the standard deviation of the proposal distribution for the Metropolis Hastings step for a_tau. Ignored if learn_a_tau is FALSE. The default value is 1.

display_progress

logical value indicating whether the progress bar and other informative output should be displayed. The default value is TRUE.

ret_beta_nc

logical value indicating whether to output the non-centered states in addition to the centered ones. The default value is FALSE.

sv

logical value indicating whether to use stochastic volatility for the error of the observation equation. For details please see stochvol, in particular svsample. The default value is FALSE.

sv_param

optional named list containing hyperparameter values for the stochastic volatility parameters. Not all have to be supplied, with those missing being replaced by the default values. Any list elements that are misnamed will be ignored and a warning will be thrown. Ignored if sv is FALSE. The following elements can be supplied:

  • Bsigma_sv: positive, real number. The default value is 1.

  • a0_sv: positive, real number. The default value is 5.

  • b0_sv: positive, real number. The default value is 1.5.

  • bmu: real number. The default value is 0.

  • Bmu: real number. larger than 0. The default value is 1.

LPDS

logical value indicating whether the one step ahead log predictive density score should be returned. If LPDS is TRUE, both x_test and y_test have to be supplied. The default value is FALSE.

y_test

optional real number. If LPDS is TRUE this value will be taken to be the true one step ahead value and will be used to calculate the log predictive density score. Ignored if LPDS is FALSE.

x_test

optional object that can be coerced to a 1 x d data frame containing the covariates for the calculation of the one step ahead log predictive density score. The column names have to exactly match the names of the covariates provided in the formula or an error will be thrown. An intercept will be added to x_test if an intercept was added to the covariates by the formula interface. Ignored if LPDS is FALSE.

Value

The value returned is a list object of class shrinkTVP_res containing

sigma2

mcmc object containing the parameter draws from the posterior distribution of sigma2. If sv is TRUE, sigma2 is additionally an mcmc.tvp object.

theta_sr

an mcmc object containing the parameter draws from the posterior distribution of the square root of theta.

beta_mean

an mcmc object containing the parameter draws from the posterior distribution of beta_mean.

beta_nc

(optional) list object containing an mcmc.tvp object for the parameter draws from the posterior distribution of the non-centered states, one for each covariate. In the case that there is only one covariate, this becomes just a single mcmc.tvp object. Not returned if ret_beta_nc is FALSE.

beta

list object containing an mcmc.tvp object for the parameter draws from the posterior distribution of the centered states, one for each covariate. In the case that there is only one covariate, this becomes just a single mcmc.tvp object.

xi2

mcmc object containing the parameter draws from the posterior distribution of xi2.

a_xi

(optional) mcmc object containing the parameter draws from the posterior distribution of a_xi. Not returned if learn_a_xi is FALSE.

a_xi_acceptance

(optional) list object containing acceptance statistics for the Metropolis Hastings algorithm for a_xi. Not returned if learn_a_xi is FALSE.

tau2

mcmc object containing the parameter draws from the posterior distribution of tau2.

a_tau

(optional) mcmc object containing the parameter draws from the posterior distribution of a_tau. Not returned if learn_a_tau is FALSE.

a_tau_acceptance

(optional) list containing acceptance statistics for the Metropolis Hastings algorithm for a_tau. Not returned if learn_a_tau is FALSE.

kappa2

(optional) mcmc object containing the parameter draws from the posterior distribution of kappa2. Not returned if learn_kappa2 is FALSE.

lambda2

(optional) mcmc object containing the parameter draws from the posterior distribution of lambda2. Not returned if learn_lambda2 is FALSE.

C0

(optional) mcmc object containing the parameter draws from the posterior distribution of C0. Not returned if sv is TRUE.

sv_mu

(optional) mcmc object containing the parameter draws from the posterior distribution of the mu parameter for the stochastic volatility model on the errors. Not returned if sv is FALSE.

sv_phi

(optional) mcmc object containing the parameter draws from the posterior distribution of the phi parameter for the stochastic volatility model on the errors. Not returned if sv is FALSE.

sv_sigma2

(optional) mcmc object containing the parameter draws from the posterior distribution of the sigma2 parameter for the stochastic volatility model on the errors. Not returned if sv is FALSE.

priorvals

list object containing hyperparameter values of the prior distributions, as specified by the user.

model

list object containing the model matrix and model response used.

summaries

list object containing a collection of summary statistics of the posterior draws.

LPDS

(optional) value of the log predictive density score, calculated with y_test and x_test.

To display the output, use plot and summary. The summary method displays the specified prior values stored in priorvals and the posterior summaries stored in summaries, while the plot method calls coda's plot.mcmc or the plot.mcmc.tvp method. Furthermore, all functions that can be appplied to coda::mcmc objects (e.g. coda::acfplot) can be applied to all output elements that are coda compatible.

Details

For details concerning the algorithm please refer to the paper by Bitto and Fr<U+00FC>hwirth-Schnatter (2019).

References

Bitto, A., & Fr<U+00FC>hwirth-Schnatter, S. (2019). "Achieving shrinkage in a time-varying parameter model framework." Journal of Econometrics, 210(1), 75-97. <doi:10.1016/j.jeconom.2018.11.006>

See Also

plot.shrinkTVP_res, plot.mcmc.tvp

Examples

Run this code
# NOT RUN {
## Example 1, learn everything
set.seed(123)
sim <- simTVP(theta = c(0.2, 0, 0), beta_mean = c(1.5, -0.3, 0))
data <- sim$data

res <- shrinkTVP(y ~ x1 + x2, data = data)
# summarize output
summary(res)


## Example 2, hierarchical Bayesian Lasso
res <- shrinkTVP(y ~ x1 + x2, data = data,
                learn_a_xi = FALSE, learn_a_tau = FALSE,
                a_xi = 1, a_tau = 1)


## Example 3, non-hierarchical Bayesian Lasso
res <- shrinkTVP(y ~ x1 + x2, data = data,
                learn_a_xi = FALSE, learn_a_tau = FALSE,
                a_xi = 1, a_tau = 1,
                learn_kappa2 = FALSE, learn_lambda2 = FALSE)


## Example 4, adding stochastic volatility
res <- shrinkTVP(y ~ x1 + x2, data = data,
                sv = TRUE)


## Example 4, changing some of the default hyperparameters
res <- shrinkTVP(y ~ x1 + x2, data = data,
                hyperprior_param = list(cp = 5,
                                        nu_xi = 10))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab