mskf: Fit A Markov Switching State-Space Model

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

View source: R/mskf.R

Description

Fit a regime switching state-space model to a (multivariate) time series.

Usage

1
2
mskf(model, method = "L-BFGS-B", hessian = TRUE, control = list(trace = 3, maxit = 500),
    debug = FALSE)

Arguments

model

Object returned by mskfModel

method

Optimization method to be used by optim

hessian

Logical. Should a numerically differentiated Hessian matrix be returned?

control

A list of control parameters. See Details in optim

debug

Logical. For debugging purposes.

Details

The model object describes a Markov regime switching state-space model for uni- or multivariate time series. The multivariate time series are assumed to be indicators for an underlying stochastic time series that is described by a state space model. The dynamics of the underlying series is assumed to switch between a discrete set of states, or regimes, each associated with their own set of parameters. Switching between regimes is modeled as a discrete time Markov chain. See mskfModel for a detail model specification. The (unconstraint) parameters and switching probabilities are estimated by means of maximum likelihood.

Missing values are treated as discussed in the last reference.

Value

An object of class mskf with components returned by optim.

Author(s)

Ellen L. Hamaker and Raoul P. P. P. Grasman

References

Kim, C.-J. (1994). Dynamic linear models with Markov-switching. Journal of Econometrics, 60, 1-22.

Kim, C.-J., and Nelson, C. R. (1999). State-Space Models with Regime Switching: Classical and Gibbs-Sampling Approaches with Applications. Cambridge, MIT press.

Hamaker, E. L., & Grasman, R. P. P. P. (2012). Regime Switching State-Space Models Applied To Psychological Processes: Handling Missing Data And Making Inferences. Psychometrika, 77:2, 400–422.

See Also

See Also as mskfModel, mskfModelSkeleton, optim

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
### Univariate AR(1) with two regimes

c = array(c(0,3), dim = c(1,2))
H = array(c(0.5, 0.3), dim = c(1,1,2))
G = array(c(1, 1), dim = c(1,1,2))

p = matrix(c(0.7, 0.3, 0.2, 0.8), 2, 2)

# specify model
skel = mskfModelSkeleton(rnorm(100), ne = 1, nm = 2)
mdl = mskfModel(skel, map = p, maH = H, maG = G)

# simulate from model
sim = simulate(mdl, nt=100)
y = sim$y;

## estimate model parameters

# set up model skeleton for simulated data
skel2 = mskfModelSkeleton(y, ne = 1, nm = 2)

# build model and initialize starting values
mdl2 = mskfModel(skel2, pap = diag(7:8), paK = 5:6, pac=1:2, paH=3:4, upper = 50, lower = -50)
startValues(mdl2, 'pac') = c(`1` = .05, `2` = 3)
startValues(mdl2, 'paH') = c(`3` = .51, `4` = .22)
startValues(mdl2, 'paK') = c(`5` = 1.5, `6` = 2)
startValues(mdl2, 'pap') = diag(c(1,.5))

# fit the model
mskf(mdl2)




### Univeriate AR(1) with two regimes and 4 indicators

B = array(c(10), dim = c(1, 1, 2))
W = array(rep(c(1, 0.8, 0.6, 0.4), 2), dim = c(4, 1, 2))
R = array(c(diag(1,4), diag(1.2,4)), dim = c(4,4,2))

# simulate from model
y = matrix(rnorm(100*4),100) # data place holder
x = rep(1, 100)
skel3 = mskfModelSkeleton(y, ne = 1, nm = 2, x=x, ipat=c(W=2,B=2,R=2,H=2,c=2,G=1,K=2,p=2))
mdl3 = mskfModel(skel3, map = p, mac = c, maH = H, maB=B, maG = G, maW = W, maR = R)
sim = simulate(mdl3)
y = sim$y

# set up model skeleton for simulated data
skel4 = mskfModelSkeleton(y, ne = 1, nm = 2, x=x, ipat=c(W=2,B=2,R=2,H=2,c=2,G=1,K=2,p=2))

# build model and initialize starting values
mdl4 = mskfModel(skel4, paW = rep(0:3,2), paB = 4:7, paR = c(diag(8:11),diag(12:15)),
	paH = 16:17, pac = c(0,18),paK = 19:20, pap = diag(21:22))

startValues(mdl4, 'paW')[] = c(0,.8, .6, .4)
startValues(mdl4, 'paB')[] = rep(10, 4)
startValues(mdl4, 'paR')[] = rep(1, 8)
startValues(mdl4, 'paH')[] = c(.5, .2)
startValues(mdl4, 'pac')[] = 3
startValues(mdl4, 'paK')[] = c(1,1)
startValues(mdl4, 'pap')[] = c(.8, 1.4)

mskf documentation built on May 2, 2019, 6:47 p.m.