updateTVP | R Documentation |
shrinkTVP
with minimal overheadupdateTVP
draws a single sample from the joint posterior distribution of the parameters of a time-varying
parameter model with shrinkage potentially including stochastic volatility (SV). It performs no input checks and must
therefore be used with caution. It is designed to be used in a modular fashion within other samplers, where speed is important.
As such, no draws are saved and must be stored manually if the user wants to analyze them further.
updateTVP(
y,
x,
curr_draws,
mod_type = "double",
learn_a_xi = TRUE,
learn_a_tau = TRUE,
a_xi = 0.1,
a_tau = 0.1,
learn_c_xi = TRUE,
learn_c_tau = TRUE,
c_xi = 0.1,
c_tau = 0.1,
a_eq_c_xi = FALSE,
a_eq_c_tau = FALSE,
learn_kappa2_B = TRUE,
learn_lambda2_B = TRUE,
kappa2_B = 20,
lambda2_B = 20,
hyperprior_param,
sv = FALSE,
sv_param,
MH_tuning
)
y |
vector of length N containing the response variable. |
x |
matrix of dimension Nxd containing the covariates. |
curr_draws |
named list containing all the current draws from the joint posterior of the parameters. Not all values are required for all model setups. The following elements can be supplied:
|
mod_type |
character string that reads either |
learn_a_xi |
logical value indicating whether to learn a_xi, the spike parameter of the state variances.
Ignored if |
learn_a_tau |
logical value indicating whether to learn a_tau, the spike parameter of the mean of the
initial values of the states. Ignored if |
a_xi |
positive, real number, indicating the (fixed) value for a_xi. Ignored if
|
a_tau |
positive, real number, indicating the (fixed) value for a_tau. Ignored if
|
learn_c_xi |
logical value indicating whether to learn c_xi, the tail parameter of the state variances.
Ignored if |
learn_c_tau |
logical value indicating whether to learn c_tau, the tail parameter of the mean of the
initial values of the states. Ignored if |
c_xi |
positive, real number, indicating the (fixed) value for c_xi. Ignored if
|
c_tau |
positive, real number, indicating the (fixed) value for c_tau. Ignored if
|
a_eq_c_xi |
logical value indicating whether to force |
a_eq_c_tau |
logical value indicating whether to force |
learn_kappa2_B |
logical value indicating whether to learn kappa2_B, the global level of shrinkage for
the state variances. The default value is |
learn_lambda2_B |
logical value indicating whether to learn the lambda2_B parameter,
the global level of shrinkage for the mean of the initial values of the states. The default value is |
kappa2_B |
positive, real number, indicating the (fixed) value for kappa2_B. Ignored if
|
lambda2_B |
positive, real number, indicating the (fixed) value for lambda2_B. Ignored if
|
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:
|
sv |
logical value indicating whether to use stochastic volatility for the error of the observation
equation. For details please see |
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
|
MH_tuning |
optional named list containing values used to tune the MH steps for
|
The value returned is a named list object which can be immediately used as the curr_draws
argument
for another draw from the posterior with updateTVP
. Note that, depending on the model setup, some elements may be matrices of dimension zero.
It contains the following elements:
beta_st |
dx(N + 1) matrix containing the current draw from the posterior distribution of beta. |
beta_mean_st |
dx1 matrix containing the current draws from the posterior distribution of beta_mean. |
theta_sr_st |
dx1 matrix containing the current draws from the posterior distribution of the square root of theta. |
tau2_st |
dx1 matrix containing the current draws from the posterior distribution of tau2. |
xi2_st |
dx1 matrix containing the current draws from the posterior distribution of xi2. |
lambda2_st |
dx1 matrix containing the current draws from the posterior distribution of lambda2. |
kappa2_st |
dx1 matrix containing the current draws from the posterior distribution of kappa2. |
a_xi_st |
number representing the current draw from the posterior distribution of a_xi. |
a_tau_st |
number representing the current draw from the posterior distribution of a_tau. |
c_xi_st |
number representing the current draw from the posterior distribution of c_xi. |
c_tau_st |
number representing the current draw from the posterior distribution of c_tau. |
lambda2_B_st |
number representing the current draw from the posterior distribution of lambda2_B. |
kappa2_B_st |
|
sigma2_st |
number if |
C0_st |
number representing the current draw from the posterior distribution of C0. |
sv_mu_st |
number representing the current draw from the posterior distribution of the mu parameter for the stochastic volatility model on the errors. |
sv_phi_st |
number representing the current draw from the posterior distribution of the phi parameter for the stochastic volatility model on the errors. |
sv_sigma2_st |
number representing the current draw from the posterior distribution of the sigma2 parameter for the stochastic volatility model on the errors. |
h0_st |
number representing the current draw from the posterior distribution of the h0 parameter for the stochastic volatility model on the errors. |
internals |
|
Peter Knaus peter.knaus@wu.ac.at
Bitto, A., & Frü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>
Cadonna, A., Frühwirth-Schnatter, S., & Knaus, P. (2020). "Triple the Gamma—A Unifying Shrinkage Prior for Variance and Variable Selection in Sparse State Space and TVP Models." Econometrics, 8(2), 20. <doi:10.3390/econometrics8020020>
Knaus, P., Bitto-Nemling, A., Cadonna, A., & Frühwirth-Schnatter, S. (2021) "Shrinkage in the Time-Varying Parameter Model Framework Using the R
Package shrinkTVP
."
Journal of Statistical Software 100(13), 1–32.<doi:10.18637/jss.v100.i13>
# Simulate data
sim <- simTVP()
y <- sim$data$y
x <- as.matrix(sim$data[,2:4])
# Create starting values
d <- ncol(x)
curr_draws <- list(beta_mean_st = rep(0, d),
theta_sr_st = rep(1, d),
tau2_st = rep(1, d),
xi2_st = rep(1, d),
lambda2_st = rep(1, d),
kappa2_B_st = 20,
lambda2_B_st = 20,
a_xi_st = 0.1,
a_tau_st = 0.1,
c_tau_st = 0.1,
sv_mu_st = -10,
sv_phi_st = 0.5,
sv_sigma2_st = 1,
C0_st = 1,
sigma2_st = 1,
h0_st = 0)
# Run the algorithm for 1000 iterations
# Note that curr_draws is always re-written and immediately re-used
for (i in 1:1000){
curr_draws <- updateTVP(y, x, curr_draws)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.