msbvar function.gibbs.msbvar(x, N1 = 1000, N2 = 1000, permute = TRUE,
upper.idx = NULL, lower.idx = NULL)N2 estimates of the state-space
matrices coded as bit objects for compression /
efficiency.msbvar. This is a reduced form MSBVAR
model. The estimation is done in a mixture of native R code and C++.
The sampling of the BVAR coefficients, the transition matrix, and the
error covariances for each regime are done in native R code. The
forward-filtering-backward-sampling of the Markov-switching process
(The most computationally intensive part of the estimation) is handled
in compiled C++ code. As such, this model is reasonably fast for
small samples / small numbers of regimes (say less than 2000
observations and 2-4 regimes). The reason for this mixed
implementation is that it is easier to setup variants of the model
(some coefficients switching, others not; different sampling methods;
etc.)The random permuation of the states is done using a multinomial step: at each draw of the Gibbs sampler, the states are permuted using a multinomial draw. This generates a posterior sample where the states are unidentified. This makes sense, since the user may have little idea of how to select among the h! posterior models of the reduced form MSBVAR model (see e.g., Fruhwirth-Schnatter (2006)). Once a posterior sample has been draw with random permuation, a clustering algorithm can be used to identify the states, for example, by examining the intercepts or covariances across the regimes (see the example below for details).
The Gibbs sampler is estimated using six steps:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The state-space for the MS process is a $T \times h$ matrix
of zeros and ones. Since this matrix classifies the observations
infor states for the N2 posterior draws, it does not make sense
to store it in double precisions. We use the bit
package to compress this matrix into a 2-bit integer representation
for more efficient storage. Functions are provided (see below) for
summarizing and plotting the resulting state-space of the MS process.
Talk about permutation and why we need it and why you need to estimate the model twice!
msbvar, plot.SS, mean.SS