# NOT RUN {
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)
# }
Run the code above in your browser using DataLab