View source: R/hsmm_functions.R
predict.hsmmspec | R Documentation |
Predicts the underlying state sequence for an observed sequence newdata
given a hsmm
model
## S3 method for class 'hsmmspec'
predict(object, newdata, method = "viterbi",M=NA, ...)
object |
An object of type |
newdata |
A vector or dataframe of observations |
method |
Prediction method (see details) |
M |
Maximum number of time spent in a state (truncates the waiting distribution) |
... |
further arguments passed to or from other methods. |
If method="viterbi"
, this technique applies the Viterbi
algorithm for HSMMs, 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 method is different to predict.hsmm in that it takes
the output from hsmmspec
as input ie. it is useful for people
who already know their model parameters.
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 |
Jared O'Connell jaredoconnell@gmail.com
Guedon, Y. (2003), Estimating hidden semi-Markov chains from discrete sequences, Journal of Computational and Graphical Statistics, Volume 12, Number 3, page 604-639 - 2003
hsmmspec
, predict.hsmm
J <- 3
init <- c(0,0,1)
P <- matrix(c(0,.1,.4,.5,0,.6,.5,.9,0),nrow=J)
B <- list(mu=c(10,15,20),sigma=c(2,1,1.5))
d <- list(lambda=c(10,30,60),shift=c(10,100,30),type='poisson')
model <- hsmmspec(init,P,parms.emission=B,sojourn=d,dens.emission=dnorm.hsmm)
train <- simulate(model,r=rnorm.hsmm,nsim=100,seed=123456)
mean(predict(model,train,M=500)$s!=train$s) #error rate when true model is known
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.