SS.ffbs: State-space forward-filter and backwards-sampler for a...

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

View source: R/gibbs.msbvar.R

Description

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

Usage

1
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

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.

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.

Note

This function assumes that the innovation in the MSBVAR model are multivariate normal. The resulting filter and sample follows that in the references listed above. This function is provided so users can build their own customized MSBVAR models. Users can write functions to generate the (B)VAR residuals for their own customized MSBVAR models than then provide the residuals and their covariances and transition matrix Q. This function can then be used to estimate / sample the regime probabilities. So if you need an MSBVAR model where only certain parameters change — rather than all of them as in the existing msbvar and gibbs.msbvar functions — you can build your own estimator using this function. This function takes care of the hard part of building an MSBVAR model.

Author(s)

Patrick T. Brandt

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

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

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

Related to SS.ffbs in MSBVAR...