hmm.discnp (version 2.1-5)

fitted.hmm.discnp: Fitted values of a discrete non-parametric hidden Markov model.

Description

Calculates the fitted 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
fitted(object, ...)

Arguments

object

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

Not used.

Value

If the observations (stored in object) 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 martrix 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 a wrapper for sp(). This latter function gets called with mean=TRUE. The fitted values are the conditional expected values of the observations, given the entire observation sequence. Note that the “conditional expected value” concept makes sense only if the observations are numeric. If this is not the case, an error is thrown. The observation sequence must be present in object (which will be the case if object was returned by hmm()). If it is not present an error is thrown.

However, if such an error is thrown, do not despair! You do not have to start from scratch when fitting your model with keep.y==TRUE. If fit is your fitted model that you obtained without setting keep.y==TRUE, then you can just re-fit the model using fit as the starting values:

      fit2 <- hmm(<whatever>,par0=fit,keep.y=TRUE)
  

This will of course converge instantaneously. You could also do:

      fit2 <- update(fit,data=<whatever>,keep.y=TRUE)
  

See Also

sp() link{predict.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)
lll <- sample(250:350,20,TRUE)
y   <- rhmm(ylengths=lll,nsim=1,drop=TRUE,tpm=P,Rho=R)
fit <- hmm(y,K=2,verb=TRUE,keep.y=TRUE,itmax=10)
fv  <- fitted(fit)
# }

Run the code above in your browser using DataLab