hmm.sim: Simulate a Gaussian hidden Markov series with / without...

Description Usage Arguments Value References Examples

Description

Simulate a Gaussian hidden Markov series with / without autoregressive structures

Usage

1
hmm.sim(ns, mod)

Arguments

ns

length of the simulated series

mod

list consisting of at least the following items: mod$m = number of states, mod$delta = vector of prior probabilities, mod$gamma = matrix of state transition probabilies. mod$mu = list of means, mod$sigma = list of covariance matrices. For autoregressive hidden markov models, we also need the additional items: mod$auto = list of autocorrelation matrices. mod$arp = order of autoregressive.

Value

a list containing simulated series and states

References

Rabiner, Lawrence R. "A tutorial on hidden Markov models and selected applications in speech recognition." Proceedings of the IEEE 77.2 (1989): 257-286.

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
set.seed(135)
#Gaussian HMM 3 hidden states (no autoregressive structure)
m <- 3
mu <- list(c(3),c(-2),c(0))
sigma <- list(as.matrix(1), as.matrix(0.8),as.matrix(0.3))
delta <- c(0.3,0.3,0.4)
gamma <- matrix(c(0.8,0.1,0.1,0.1,0.8,0.1,0.1,0.1,0.8),3,3,byrow=TRUE)
mod1 <- list(m=m,mu=mu,sigma=sigma,delta=delta,gamma=gamma)
sim1 <- hmm.sim(1000,mod1)
y1 <- sim1$series
fit1 <- em.hmm(y=y1, mod=mod1)

#AR(2) Gaussian HMM with 3 hidden states
m <- 2
mu <- list(c(3,4,5),c(-2,-3,-4))
sigma <- list(diag(1.3,3), 
            matrix(c(1,-0.3,0.2,-0.3,1.5,0.3,0.2,0.3,2),3,3,byrow=TRUE))
delta <- c(0.5,0.5)
gamma <- matrix(c(0.8,0.2,0.1,0.9),2,2,byrow=TRUE)
auto <- list(matrix(c(0.3,0.2,0.1,0.4,0.3,0.2,
                     -0.3,-0.2,-0.1,0.3,0.2,0.1,
                      0,0,0,0,0,0),3,6,byrow=TRUE),
            matrix(c(0.2,0,0,0.4,0,0,
                      0,0.2,0,0,0.4,0,
                     0,0,0.2,0,0,0.4),3,6,byrow=TRUE))
mod2 <- list(m=m,mu=mu,sigma=sigma,delta=delta,gamma=gamma,auto=auto,arp=2)
sim2 <- hmm.sim(2000,mod2)
y2 <- sim2$series
fit2 <- em.hmm(y=y2, mod=mod2, arp=2)

Example output

iteration  1 ; loglik =  -1777.694 
iteration  2 ; loglik =  -1772.407 
iteration  3 ; loglik =  -1772.029 
iteration  4 ; loglik =  -1771.931 
iteration  5 ; loglik =  -1771.902 
iteration  6 ; loglik =  -1771.894 
iteration  7 ; loglik =  -1771.892 
iteration  8 ; loglik =  -1771.891 
iteration  9 ; loglik =  -1771.89 
iteration  1 ; loglik =  -10181.56 
iteration  2 ; loglik =  -10152.32 
iteration  3 ; loglik =  -10152.32 

rarhsmm documentation built on May 2, 2019, 9:33 a.m.

Related to hmm.sim in rarhsmm...