Learn R Programming

scoringRules (version 0.9.2)

ar_ms: Bayesian analysis of a Markov Switching autoregressive model

Description

Bayesian analysis of a Markov Switching autoregressive model

Usage

ar_ms(y, nlag = 1, beta_switch = FALSE, variance_switch = TRUE,
  identification_constraint = "variance", n_burn = 5000, n_rep = 20000,
  forecast_periods = 5, printout = FALSE, Hm1_delta = 25, mu_delta = 0,
  s_ = 0.3, nu_ = 3, R = matrix(c(8, 2, 2, 8), nrow = 2))

Arguments

y

Numeric vector (time series to be analyzed).

nlag

Integer, number of autoregressive lags (defaults to one).

beta_switch, variance_switch

Logicals, indicating whether there should be Markovian state dependence in regression parameters and residual variance, respectively. Defaults to beta_switch = FALSE, variance_switch = TRUE.

identification_constraint

Character, indicating how to identify latent states. Possible values: "variance", "mean" and "persistence". Defaults to "variance".

n_burn, n_rep

Integers, number of MCMC iterations for burn-in and main analysis.

forecast_periods

Number of future periods for which forecasts are computed.

printout

Logical, whether to print progress report during MCMC (defaults to FALSE).

Hm1_delta, mu_delta, s_, nu_, R

Prior parameters as described in KLTG (2016, Appendix E and Table 5).

Value

List containing parameter estimates and forecasts, with the following elements:

  • pars, matrix of posterior draws for parameters (rows are MCMC iterations, columns are parameters)

  • fcMeans and fcSds, matrices of forecast means and standard deviations (rows are MCMC iterations, columns are forecast horizons)

  • filprobs, matrix of filtered probabilities for first latent state (rows are MCMC iterations, columns are time periods, excluding the first nlag values for initialization).

  • count, integer, counter for the number of states that were relabeled based on identification_constraint.

Details

The default parameters are as set by KLTG (2016, Section 5). The output matrices fcMeans and fcSds can be used to construct the mixture-of-parameters estimator analyzed by KLTG. While many of the model features can be changed as described above, the number of Markov regimes is always fixed at two.

ar_ms is an R/C++ implementation of Matlab code kindly shared by Gianni Amisano via his website (https://sites.google.com/site/gianniamisanowebsite/). See Amisano and Giacomini (2007) who analyze a similar model.

References

Amisano, G. and R. Giacomini (2007), `Comparing density forecasts via weighted likelihood ratio tests', Journal of Business and Economic Statistics 25, 177-190.

Krueger, F., S. Lerch, T.L. Thorarinsdottir and T. Gneiting (2016), `Probabilistic forecasting and comparative model assessment based on Markov Chain Monte Carlo output', working paper, Heidelberg Institute for Theoretical Studies, available at http://arxiv.org/abs/1608.06802.

See Also

run_casestudy uses ar_ms to replicate the results of KLTG (2016, Section 5).

Examples

Run this code
# NOT RUN {
# Use GDP data from 2014Q4 edition
data(gdp)
dat <- subset(gdp, vint == "2014Q4")
y <- dat$val[order(dat$dt)]

# Fit model, using the default settings 
set.seed(816)
fit <- ar_ms(y)

# Histograms of parameter draws
par(mfrow = c(2, 2))
hist(fit$pars[,1], main = "Intercept (state-invariant)", xlab = "")
hist(fit$pars[,2], main = "AR(1) term (state-invariant)", xlab = "")
hist(1/fit$pars[,3], main = "Residual variance in 1st state", xlab = "")
hist(1/fit$pars[,4], main = "Residual variance in 2nd state", xlab = "")

# By construction, the residual variance is smaller in the 1st than in the 2nd state:
print(mean(1/fit$pars[,3] < 1/fit$pars[,4]))
# }

Run the code above in your browser using DataLab