Learn R Programming

MSBVAR (version 0.7-1)

simulateMSVAR: Simulate a Markov-switching VAR (MSVAR) process

Description

Simulate Markov-switching vector autoregression data

Usage

simulateMSVAR(bigt, m, p, var.beta0, var.betas, e.vcv, Q, seed = 214)

Arguments

Value

A list with two elements:YThe simulated MSVAR time series in a ts object of dimension $bigt \times m$.stA vector of integers identifying the regime of each observation in Y

Details

This function simulates a multivariate Markov-switching model, MSVAR with $m$ equations, $p$ lags and $h$ regimes. The assumption is that the error process is Gaussian.

References

Kim, Chang-Jin and Charles R. Nelson. 1999. State-Space Models with Regime Switching: Classical and Gibbs-Sampling Approaches with Applications. Cambridge: MIT Press.

See Also

simulateMSAR for the univariate version; msbvar

Examples

Run this code
# Example: simulate an MS(h)-VAR(p) model with two equations.
# Have h = 2, m=2, and p=1, simplest case

# VAR simulation parameters
bigt <- 500  # number of observations
m <- 2  # number of endogenous variables
p <- 1  # lag length
h <- 2  # number of regimes

# setup transition matrix with two states

Q <- matrix(c(.98, .02,
              .05, .95), nrow=h, byrow=TRUE)

# theta stores paramater values
# 1st column is intercept
# 2:m*p are the AR coefficients
# (mp+2)'th columns are variance

# regime 1
var.beta0.st1  <- c(1,2)  # intercepts
var.betas.st1  <- matrix(c(.7, .1,
                           .1, .7), m, byrow=TRUE)
# regime 2
var.beta0.st2  <- c(0,0)  # intercepts
var.betas.st2  <- matrix(c(.2, .1,
                           .2, .1), m, byrow=TRUE)

# Build the array
var.beta0 <- array(NA, c(m,1,h))
var.betas <- array(NA, c(m,p*m,h))
var.beta0[,,1] <- var.beta0.st1
var.beta0[,,2] <- var.beta0.st2
var.betas[,,1] <- var.betas.st1
var.betas[,,2] <- var.betas.st2

# Variance-Covariance Matrix for
# MVN distributed disturbances
# regime 1
e.vcv.st1  <- matrix(c(.3, .1,
                       .1, .3), 2)
# regime 2
e.vcv.st2  <- matrix(c(.1, .05,
                       .05, .1), 2)
# combine
e.vcv <- array(NA, c(m, m, h))
e.vcv[,,1] <- e.vcv.st1
e.vcv[,,2] <- e.vcv.st2

# hold true values of parameters for easy comparison to estimates
theta.true.var <- array(NA, c(m, 1+m*p+m, h))
theta.true.var[,1,] <- var.beta0
theta.true.var[,2:(1+p*m),] <- var.betas
theta.true.var[,(1+m*p+1):ncol(theta.true.var),] <- e.vcv

simdata <- simulateMSVAR(bigt, m, p, var.beta0, var.betas, e.vcv, Q)

# Plot
plot(as.ts(simdata[[1]]))

# Fit a simple model

model <- msvar(Y=simdata[[1]], p=1, h=2, niterblkopt=50)

# Plot regime estimates and compare to true simulated values
par(mfrow=c(2,1))
plot(ts(model$fp))
plot(ts(simdata$st))

Run the code above in your browser using DataLab