ar_ms: Bayesian analysis of a Markov Switching autoregressive model

View source: R/header_replication.R

ar_msR Documentation

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 (2021, Appendix E and Table 4).

Details

The default parameters are as set by KLTG (2021, 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.

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)

  • probs, 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.

Author(s)

Fabian Krueger, based on Matlab code by Gianni Amisano (see details section)

References

Amisano, G. and R. Giacomini (2007), ‘Comparing density forecasts via weighted likelihood ratio tests’, Journal of Business and Economic Statistics 25, 177-190. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1198/073500106000000332")}

Krueger, F., Lerch, S., Thorarinsdottir, T.L. and T. Gneiting (2021): ‘Predictive inference based on Markov chain Monte Carlo output’, International Statistical Review 89, 274-301. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/insr.12405")}

See Also

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

Examples

## 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]))

## End(Not run)

scoringRules documentation built on May 31, 2023, 6:06 p.m.