# smooth.hmm: Calculate the probability of being in a particular state for... In rarhsmm: Regularized Autoregressive Hidden Semi Markov Model

## Description

Calculate the probability of being in a particular state for each observation.

## Usage

 `1` ```smooth.hmm(y, mod) ```

## Arguments

 `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. 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

## Value

a matrix containing the state probabilities

## 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``` ```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.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)) mod <- list(m=m,mu=mu,sigma=sigma,delta=delta,gamma=gamma,auto=auto,arp=2) sim <- hmm.sim(2000,mod) y <- sim\$series state <- sim\$state fit <- em.hmm(y=y, mod=mod, arp=2) stateprob <- smooth.hmm(y=y,mod=fit) head(cbind(state,stateprob),20) ```

### Example output

```iteration  1 ; loglik =  -10052.34
iteration  2 ; loglik =  -10014.45
iteration  3 ; loglik =  -10014.45
state
[1,]     1 1.000000e+00 3.211755e-139
[2,]     1 1.000000e+00  4.256785e-40
[3,]     1 1.000000e+00  6.211848e-37
[4,]     1 1.000000e+00  3.070092e-40
[5,]     1 1.000000e+00  1.890428e-25
[6,]     2 2.533539e-34  1.000000e+00
[7,]     2 1.300674e-17  1.000000e+00
[8,]     2 1.202568e-20  1.000000e+00
[9,]     1 1.000000e+00  1.227771e-22
[10,]     1 1.000000e+00  2.649681e-23
[11,]     1 1.000000e+00  1.640768e-33
[12,]     1 1.000000e+00  1.252117e-32
[13,]     1 1.000000e+00  6.673570e-36
[14,]     1 1.000000e+00  7.154855e-36
[15,]     1 1.000000e+00  9.100629e-34
[16,]     2 8.020779e-32  1.000000e+00
[17,]     1 1.000000e+00  3.188145e-19
[18,]     1 1.000000e+00  3.385804e-26
[19,]     1 1.000000e+00  1.537049e-31
[20,]     1 1.000000e+00  3.535321e-33
```

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