Learn R Programming

MSBVAR (version 0.9-2)

SS.ffbs: State-space forward-filter and backwards-sampler for a Markov-switching VAR model

Description

This function estimates the $h$ state probabilities for all of the observations for a Gaussian likelihood

Usage

SS.ffbs(e, bigt, m, p, h, sig2, Q)

Arguments

e
$TT x m x h$ array of the residuals for an MSBVAR process
bigt
integer, number of observations in the model
m
integer, number of equations or variables in the MSBVAR model
p
integer, number of lags in the model
h
integer, number of regimes in the MSBVAR model
sig2
$m x m x h$ array of the covariances for each regime (can be the same for each of the $h$ regimes)
Q
$h x h$ first order Markov transition matrix; each row must sum to 1

Value

A $T x h$ matrix of the sampled regimes. Each row corresponds to an identity matrix element giving the regime classification for the observation.

Details

The estimation of an MSBVAR model requires and efficient classifier of the states for the observed filtered probabilities. This function provides a way to accomplish this and is one of the workhorses in the estimation in the msbvar and gibbs.msbvar function.

This function uses compiled Fortran code to draw the 0-1 matrix of the regimes. It uses the Baum-Hamilton-Lee-Kim (BHLK) filter and smoother to estimate the regime probabilities. Draws are based on the standard forward-filter-backward-sample algorithm.

References

Kim, C.J. and C.R. Nelson. 1999. State-space models with regime switching. Cambridge, Mass: MIT Press.

Krolzig, Hans-Martin. 1997. Markov-Switching Vector Autoregressions: Modeling, Statistical Inference, and Application to Business Cycle Analysis. Sims, Christopher A. and Daniel F. Waggoner and Tao Zha. 2008. "Methods for inference in large multiple-equation Markov-switching models" Journal of Econometrics 146(2):255--274.

See Also

msbvar, gibbs.msbvar

Examples

Run this code
# Simple example to show how data are input to the filter-sampler.
# Assumes a simple bivariate regression model with switching means and
# variances.

TT <- 100
h <- 2
m <- 2
set.seed(123)
x1 <- rnorm(TT)
x2 <- rnorm(TT)
y1 <- 5 + 2*x1 + rnorm(TT)
y2 <- 1 + x2 + 5*rnorm(TT)

Y <- rbind(cbind(y1[1:(0.5*TT)],y2[1:(0.5*TT)]),
           cbind(y2[((0.5*TT)+1):TT],y1[((0.5*TT)+1):TT]))
X <- rbind(cbind(x1[1:(0.5*TT)],x2[1:(0.5*TT)]),
           cbind(x2[((0.5*TT)+1):TT],x1[((0.5*TT)+1):TT]))

u1 <- Y - tcrossprod(cbind(rep(1,TT), X), matrix(c(5,2,0,1,1,0), 2, 3))
u2 <- Y - tcrossprod(cbind(rep(1,TT), X), matrix(c(1,1,0,5,2,0), 2, 3))

u <- array(0, c(TT, m, h))
u[,,1] <- u1
u[,,2] <- u2

Sik <- array(0, c(m,m,h))
Sik[,,1] <- diag(c(1,25))
Sik[,,2] <- diag(c(25,1))

Q <- matrix(c(0.9,0.2,0.1,0.8), h, h)

# estimate the states 100 times
ss <- replicate(100, SS.ffbs(u, TT, m, p=1, h, Sik, Q), simplify=FALSE)

# Get the state estimates from the 100 simulations
ss.est <- matrix(unlist(ss), nrow=(h*TT + h^2))

ss.prob <- matrix(rowMeans(ss.est[1:(h*TT),]), ncol=h)
ss.transition <- matrix(rowMeans(ss.est[((h*TT)+1):((h*TT) + h^2),]),
                        h, h)

Run the code above in your browser using DataLab