predict.hmm.discnp {hmm.discnp} | R Documentation |
Predicted values of a discrete non-parametric hidden Markov model.
Description
Calculates predicted values given a specification of a discrete
non-parametric hidden Markov model. The specification may be
provided in the form of a hmm.discnp
object as returned
by hmm()
or in the form of “components” of such
a model: the data y
, the transition probability matrix
tpm
, the emission probabilities Rho
, etc. If the
data are numeric then these predicted values are the conditional
expectations of the observations, given the entire observation
sequence (and the — possibly estimated — parameters of the
model). If the data are categorical (whence “expectations”
make no sense) the “predicted values” are taken to be the
probabilities of each of the possible values of the observations,
at each time point.
Usage
## S3 method for class 'hmm.discnp'
predict(object, y = NULL, tpm=NULL, Rho=NULL,
ispd=NULL, X=NULL,addIntercept=NULL,
warn=TRUE, drop=TRUE, ...)
Arguments
object |
If not |
y |
A data structure to which the fitted model |
tpm , Rho , ispd , X , addIntercept , warn |
See the help for |
drop |
Logical scalar. See the help for
|
... |
Not used. |
Details
This function is essentially the same as
fitted.hmm.discnp()
. The main difference is
that it allows the calculation of fitted/predicted values for a
data object y
possibly different from that to which the
model was fitted. Note that if both the argument y
and
object[["y"]]
are present, the “argument” value takes
precedence. This function also allows the model to be specfied
in terms of individual components rather than as a fitted model
of class "hmm.discnp"
. These components, (tpm
,
Rho
, ispd
, X
, addIntercept
) if
supplied, take precedence over the corresponding components
of object
. The opposite applies with sp()
. The
function fitted.hmm.discnp()
makes use only
of the components of object
.
Value
See the help for fitted.hmm.discnp()
.
Author(s)
Rolf Turner
r.turner@auckland.ac.nz
See Also
sp()
link{fitted.hmm.discnp}()
Examples
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)
yval <- letters[1:5]
set.seed(171)
y3 <- rhmm(ylengths=ll2,yval=yval,nsim=1,tpm=P,Rho=R,drop=TRUE)
fit3 <- hmm(y3,K=2,verb=TRUE,keep.y=TRUE,itmax=10)
pv3 <- predict(fit3) # Same as fitted(fit3).