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

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/simulateMSVAR.R

Description

Simulate Markov-switching vector autoregression data

Usage

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

Arguments

bigt

Integer, number of observations to generate.

m

Integer, number of equations in the VAR process

p

Integer, lag length of the VAR(p) process.

var.beta0

Array of dimension m x 1 x h of the VAR intercepts for each regime (h)

var.betas

Array of dimension m x mp x h of the autoregressive coefficients. In each element of the array, rows correspond to equations, columns to lags. The first m x m columns are the AR(1) coefficients, etc.

e.vcv

Array of dimentsion m x m x h of the error covariances. The m x m matrices are the error covariances for each regime.

Q

h dimensional transition matrix for the MS process. h x h Markov transition matrix whose rows sum to 1 with the main weights on the diagonal elements.

seed

Integer. Random number seed.

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.

Value

A list with two elements:

Y

The simulated MSVAR time series in a ts object of dimension bigt x m.

st

A vector of integers identifying the regime of each observation in Y

Author(s)

Patrick T. Brandt and Ryan Davis

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
## Not run: 
# 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))

## End(Not run)

Example output

##
## MSBVAR Package v.0.9-2
## Build date:  Thu Nov 15 08:47:44 2018 
## Copyright (C) 2005-2018, Patrick T. Brandt
## Written by Patrick T. Brandt
##
## Support provided by the U.S. National Science Foundation
## (Grants SES-0351179, SES-0351205, SES-0540816, and SES-0921051)
##

Initial Log Likelihood Value: -20903.82 
Starting blockwise optimization over 50 block optimizations...
Completed iteration 1 of 50. Log Likelihood Value: -2076.051
Completed iteration 2 of 50. Log Likelihood Value: -1438.568
Completed iteration 3 of 50. Log Likelihood Value: -1429.498
Completed iteration 4 of 50. Log Likelihood Value: -1423.105
Completed iteration 5 of 50. Log Likelihood Value: -1418.33
Completed iteration 6 of 50. Log Likelihood Value: -1414.757
Completed iteration 7 of 50. Log Likelihood Value: -1412.083
Completed iteration 8 of 50. Log Likelihood Value: -1410.082
Completed iteration 9 of 50. Log Likelihood Value: -1408.585
Completed iteration 10 of 50. Log Likelihood Value: -1407.465
Completed iteration 11 of 50. Log Likelihood Value: -1406.627
Completed iteration 12 of 50. Log Likelihood Value: -1406
Completed iteration 13 of 50. Log Likelihood Value: -1405.531
Completed iteration 14 of 50. Log Likelihood Value: -1405.18
Completed iteration 15 of 50. Log Likelihood Value: -1404.917
Completed iteration 16 of 50. Log Likelihood Value: -1404.72
Completed iteration 17 of 50. Log Likelihood Value: -1404.573
Completed iteration 18 of 50. Log Likelihood Value: -1404.463
Completed iteration 19 of 50. Log Likelihood Value: -1404.381
Completed iteration 20 of 50. Log Likelihood Value: -1404.319
Completed iteration 21 of 50. Log Likelihood Value: -1404.273
Completed iteration 22 of 50. Log Likelihood Value: -1404.239
Completed iteration 23 of 50. Log Likelihood Value: -1404.213
Completed iteration 24 of 50. Log Likelihood Value: -1404.193
Completed iteration 25 of 50. Log Likelihood Value: -1404.179
Completed iteration 26 of 50. Log Likelihood Value: -1404.168
Completed iteration 27 of 50. Log Likelihood Value: -1404.16
Completed iteration 28 of 50. Log Likelihood Value: -1404.154
Completed iteration 29 of 50. Log Likelihood Value: -1404.149
Completed iteration 30 of 50. Log Likelihood Value: -1404.146
Completed iteration 31 of 50. Log Likelihood Value: -1404.144
Completed iteration 32 of 50. Log Likelihood Value: -1404.142
Completed iteration 33 of 50. Log Likelihood Value: -1404.14
Completed iteration 34 of 50. Log Likelihood Value: -1404.139
Completed iteration 35 of 50. Log Likelihood Value: -1404.138
Completed iteration 36 of 50. Log Likelihood Value: -1404.138
Completed iteration 37 of 50. Log Likelihood Value: -1404.137
Completed iteration 38 of 50. Log Likelihood Value: -1404.137
Completed iteration 39 of 50. Log Likelihood Value: -1404.137
Completed iteration 40 of 50. Log Likelihood Value: -1404.137
Completed iteration 41 of 50. Log Likelihood Value: -1404.136
Completed iteration 42 of 50. Log Likelihood Value: -1404.136
Completed iteration 43 of 50. Log Likelihood Value: -1404.136
Completed iteration 44 of 50. Log Likelihood Value: -1404.136
Completed iteration 45 of 50. Log Likelihood Value: -1404.136
Completed iteration 46 of 50. Log Likelihood Value: -1404.136
Completed iteration 47 of 50. Log Likelihood Value: -1404.136
Completed iteration 48 of 50. Log Likelihood Value: -1404.136
Completed iteration 49 of 50. Log Likelihood Value: -1404.136
Completed iteration 50 of 50. Log Likelihood Value: -1404.136

MSBVAR documentation built on May 30, 2017, 1:23 a.m.

Related to simulateMSVAR in MSBVAR...