predict.hmmspec {mhsmm}R Documentation

Prediction function for hmmspec

Description

Predicts the underlying state sequence for an observed sequence newdata given a hmmspec model

Usage

## S3 method for class 'hmmspec'
predict(object, newdata,method = "viterbi", ...)

Arguments

object

An object of class hmm

newdata

A vector or list of observations

method

Prediction method (see details)

...

further arguments passed to or from other methods.

Details

If method="viterbi", this technique applies the Viterbi algorithm for HMMs, producing the most likely sequence of states given the observed data. If method="smoothed", then the individually most likely (or smoothed) state sequence is produced, along with a matrix with the respective probabilities for each state. This function differs from predict.hmm in that it takes the output from hmmspec ie. this is useful when users already know their parameters and wish to make predictions.

Value

Returns a hsmm.data object, suitable for plotting.

newdata

A vector or list of observations

s

A vector containing the reconstructed state sequence

N

The lengths of each sequence

p

A matrix where the rows represent time steps and the columns are the probability for the respective state (only produced when method="smoothed")

Author(s)

Jared O'Connell jaredoconnell@gmail.com

References

Rabiner, L. (1989), A tutorial on hidden Markov models and selected applications in speech recognition, Proceedings of the IEEE, 77, 257-286.

See Also

hmmspec

Examples

     J<-3
     initial <- rep(1/J,J)
     P <- matrix(c(.8,.5,.1,0.05,.2,.5,.15,.3,.4),nrow=J)
     b <- list(mu=c(-3,0,2),sigma=c(2,1,.5))
     model <- hmmspec(init=initial, trans=P, parms.emission=b,dens.emission=dnorm.hsmm)    
     train <- simulate(model, nsim=300, seed=1234, rand.emis=rnorm.hsmm)
     mean(predict(model,train)$s!=train$s) #error rate when true model is known

[Package mhsmm version 0.4.21 Index]