hmm.discnp (version 2.1-5)

predict.hmm.discnp: Predicted values of a discrete non-parametric hidden Markov model.

Description

Calculates the predicted values of a discrete non-parametric hidden Markov model as the conditional expectations of the observations, given the entire observation sequence (and the [estimated] parameters of the model).

Usage

# S3 method for hmm.discnp
predict(object, y=NULL, ...)

Arguments

object

An object of class hmm.discnp as returned by hmm().

y

A data structure from which the fitted model object could have been fitted.

Not used.

Value

If the observations (stored in y) consist of a single sequence, then the object returned is a matrix. If the model is univariate (see hmm()) then matrix has a single column constituting the corresponding sequence of fitted values. If the model is bivariate (either independent or dependent) then the matrix has two columns corresponding respectively to the two variables in the bivariate model. If the observations consist of a list of observation sequences, then the object returned is a list of corresponding matrices whose columns are the fitted values.

Details

This function is essentially the same as fitted.hmm.discnp(), except that it allows the calculation of fitted/predicted values for a data object possibly different from that to which the model was fitted. Like fitted.hmm.discnp() this function is essentially a wrapper for sp(). Note that the predicted values are calculated as “conditional expected values” which makes sense only if the observations are numeric. If this is not the case, an error is thrown. If the observation list y is not supplied then it is taken to be the y component of object. If there is no such component (i.e. if object is the value returned from hmm() with the argument keep.y set equal to FALSE) then an error is thrown.

See Also

sp() link{fitted.hmm.discnp}()

Examples

Run this code
# NOT RUN {
P <- matrix(c(0.7,0.3,0.1,0.9),2,2,byrow=TRUE)
R <- matrix(c(0.5,0,0.1,0.1,0.3,
              0.1,0.1,0,0.3,0.5),5,2)
set.seed(42)
ll1 <- sample(250:350,20,TRUE)
y1  <- rhmm(ylengths=ll1,nsim=1,tpm=P,Rho=R,drop=TRUE)
fit <- hmm(y1,K=2,verb=TRUE,keep.y=TRUE,itmax=10)
fv  <- fitted(fit)
set.seed(176)
ll2 <- sample(250:350,20,TRUE)
y2  <- rhmm(ylengths=ll2,nsim=1,tpm=P,Rho=R,drop=TRUE)
pv  <- predict(fit,y=y2)
# }

Run the code above in your browser using DataCamp Workspace