hmmviterbi: Viterbi algorithm to decode the latent states for hidden...

Description Usage Arguments Value References Examples

View source: R/hmmviterbi.R

Description

Viterbi algorithm to decode the latent states for hidden Markov models

Usage

1
2
hmmviterbi(y, ntimes = NULL, M, prior_init, tpm_init, emit_init, zero_init,
  plot = FALSE, xlim = NULL, ylim = NULL, ...)

Arguments

y

the observed series to be decoded

ntimes

vector specifying the lengths of individual, i.e. independent, time series. If not specified, the responses are assumed to form a single time series, i.e. ntimes=length(y)

M

number of latent states

prior_init

a vector of prior probability values

tpm_init

transition probability matrix

emit_init

a vector containing means for each poisson distribution

zero_init

a vector containing structural zero proportions in each state

plot

whether a plot should be returned

xlim

vector specifying the minimum and maximum on the x-axis in the plot. Default to NULL.

ylim

vector specifying the minimum and maximum on the y-axis in the plot. Default to NULL.

...

further arguments to be passed to the plot() function

Value

the decoded series of latent states

References

Walter Zucchini, Iain L. MacDonald, Roland Langrock. Hidden Markov Models for Time Series: An Introduction Using R, Second Edition. Chapman & Hall/CRC

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
prior_init <- c(0.5,0.2,0.3)
emit_init <- c(10,40,70)
zero_init <- c(0.5,0,0)
omega <- matrix(c(0.5,0.3,0.2,0.4,0.3,0.3,0.2,0.4,0.4),3,3,byrow=TRUE)
result <- hmmsim(n=1000,M=3,prior=prior_init, tpm_parm=omega,
         emit_parm=emit_init,zeroprop=zero_init)
y <- result$series
state <- result$state
fit <- hmmfit(y=y,M=3,prior_init=prior_init,tpm_init=omega,
     emit_init=emit_init,zero_init=zero_init,
     method="Nelder-Mead",hessian=FALSE,control=list(maxit=500,trace=1))

decode <- hmmviterbi(y,NULL,3,fit$prior,fit$tpm,fit$emit_parm,fit$zeroprop,
                      plot=TRUE,xlab="Time",ylab="Count")      
#check the missclassification rate
sum(decode!=state)/length(state)      

## Not run: 
decode <- hmmviterbi(y,NULL,3,fit$prior,fit$tpm,fit$emit_parm,fit$zeroprop,
                      plot=TRUE,xlim=c(0,100),ylim=c(0,100),
                      xlab="Time",ylab="Count")  

## End(Not run)

ziphsmm documentation built on May 2, 2019, 6:10 a.m.

Related to hmmviterbi in ziphsmm...