set.seed(123)
n.seq <- 200
p <- 5
K <- 2
mix.prop <- c(0.3, 0.7)
TP1 <- matrix(c(0.20, 0.10, 0.15, 0.15, 0.40,
0.20, 0.20, 0.20, 0.20, 0.20,
0.15, 0.10, 0.20, 0.20, 0.35,
0.15, 0.10, 0.20, 0.20, 0.35,
0.30, 0.30, 0.10, 0.10, 0.20), byrow = TRUE, ncol = p)
TP2 <- matrix(c(0.15, 0.15, 0.20, 0.20, 0.30,
0.20, 0.10, 0.30, 0.30, 0.10,
0.25, 0.20, 0.15, 0.15, 0.25,
0.25, 0.20, 0.15, 0.15, 0.25,
0.10, 0.30, 0.20, 0.20, 0.20), byrow = TRUE, ncol = p)
TP <- array(rep(NA, p * p * K), c(p, p, K))
TP[,,1] <- TP1
TP[,,2] <- TP2
# DATA SIMULATION
A <- click.sim(n = n.seq, int = c(10, 50), alpha = mix.prop, gamma = TP)
C <- click.read(A$S)
# EM ALGORITHM
M2 <- click.EM(X = C$X, y = C$y, K = 2)
# Assuming component probabilities given by mixing proportions, predict the next state
click.predict(M = 1, gamma = M2$gamma, pr = M2$alpha)
# For the last location in the first sequence, predict the three-step transition
# location, given corresponding posterior probabilities
click.predict(M = 3, gamma = M2$gamma, pr = M2$z[1,])[A$S[[1]][length(A$S[[1]])],]
Run the code above in your browser using DataLab