Description Usage Arguments Value References Examples
Calculate the probability of being in a particular state for each observation.
1 | smooth.semi(y, mod)
|
y |
observed series |
mod |
list consisting the at least the following items: mod$m = scalar number of states, mod$delta = vector of initial values for prior probabilities, mod$gamma = matrix of initial values for state transition probabilies. mod$mu = list of initial values for means, mod$sigma = list of initial values for covariance matrices. mod$d = list of state duration probabilities. For autoregressive hidden markov models, we also need the additional items: mod$arp = scalar order of autoregressive structure mod$auto = list of initial values for autoregressive coefficient matrices |
a matrix containing the state probabilities
Rabiner, Lawrence R. "A tutorial on hidden Markov models and selected applications in speech recognition." Proceedings of the IEEE 77.2 (1989): 257-286.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | set.seed(15562)
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))
mod <- list(m=m,mu=mu,sigma=sigma,delta=delta,gamma=gamma,
auto=auto,arp=2,d=d)
sim <- hsmm.sim(2000,mod)
y <- sim$series
state <- sim$state
fit <- em.semi(y=y, mod=mod, arp=2)
stateprob <- smooth.semi(y=y,mod=fit)
head(cbind(state,stateprob),20)
|
iteration 1 ; loglik = -10528.78
iteration 2 ; loglik = -10503.73
state 1 2
[1,] 1 1.000000e+00 5.957608e-53
[2,] 1 1.000000e+00 5.356154e-34
[3,] 1 1.000000e+00 1.975280e-35
[4,] 1 1.000000e+00 6.290035e-48
[5,] 2 1.800191e-50 1.000000e+00
[6,] 1 1.000000e+00 1.327076e-19
[7,] 1 1.000000e+00 7.359963e-35
[8,] 1 1.000000e+00 1.077423e-27
[9,] 1 1.000000e+00 1.817945e-54
[10,] 2 7.185814e-39 1.000000e+00
[11,] 2 1.549371e-41 1.000000e+00
[12,] 1 1.000000e+00 1.482615e-22
[13,] 1 1.000000e+00 1.444602e-25
[14,] 2 9.598501e-28 1.000000e+00
[15,] 1 1.000000e+00 4.141223e-47
[16,] 2 1.255110e-32 1.000000e+00
[17,] 2 7.262155e-30 1.000000e+00
[18,] 2 7.083572e-52 1.000000e+00
[19,] 1 1.000000e+00 1.817082e-60
[20,] 2 5.073122e-41 1.000000e+00
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.