# hsmm.sim: Simulate a Gaussian hidden semi-Markov series with / without... In rarhsmm: Regularized Autoregressive Hidden Semi Markov Model

## Description

Simulate a Gaussian hidden semi-Markov series with / without autoregressive structures

## Usage

 1 hsmm.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. mod\$d = list of state duration probabilities. 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 30 31 32 33 34 35 set.seed(351) #Gaussian HSMM 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,0.5,0.5,0.5,0,0.5,0.5,0.5,0),3,3,byrow=TRUE) d <- list(c(0.4,0.3,0.2,0.1), c(0.5,0.25,0.25), c(0.7,0.3)) mod1 <- list(m=m,mu=mu,sigma=sigma,delta=delta,gamma=gamma,d=d) sim1 <- hsmm.sim(500,mod1) y1 <- sim1\$series fit1 <- em.semi(y=y1, mod=mod1) ## Not run: #AR(2) Gaussian HSMM 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,1,1,0),2,2,byrow=TRUE) d <- list(c(0.4,0.2,0.1,0.1,0.1,0.1),c(0.5,0.3,0.2)) 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,d=d) sim2 <- hsmm.sim(2000,mod2) y2 <- sim2\$series fit2 <- em.semi(y=y2, mod=mod2, arp=2) ## End(Not run)

### Example output

iteration  1 ; loglik =  -1025.779
iteration  2 ; loglik =  -1019.649
iteration  3 ; loglik =  -1019.411
iteration  4 ; loglik =  -1019.362
iteration  5 ; loglik =  -1019.344
iteration  6 ; loglik =  -1019.334
iteration  7 ; loglik =  -1019.328
iteration  8 ; loglik =  -1019.324
iteration  9 ; loglik =  -1019.321
iteration  10 ; loglik =  -1019.319
iteration  11 ; loglik =  -1019.317
iteration  12 ; loglik =  -1019.316
iteration  13 ; loglik =  -1019.315
iteration  14 ; loglik =  -1019.314
iteration  1 ; loglik =  -35069.29
iteration  2 ; loglik =  -27317.43
iteration  3 ; loglik =  -25924.26
iteration  4 ; loglik =  -25238.04
iteration  5 ; loglik =  -24829.38
iteration  6 ; loglik =  -24445.05
iteration  7 ; loglik =  -23891.5
iteration  8 ; loglik =  -23539.6
iteration  9 ; loglik =  -23468.22

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