View source: R/fitted.hmm.discnp.R
fitted.hmm.discnp | R Documentation |
Calculates the fitted values of a discrete non-parametric hidden Markov model. If the data are numeric these are the conditional expectations of the observations, given the entire observation sequence (and the estimated parameters of the model). If the data are categorical (whence “expectations” make no sense) the “fitted values” are taken to be the probabilities of each of the possible values of the observations, at each time point.
## S3 method for class 'hmm.discnp' fitted(object, warn=TRUE, drop=TRUE, ...)
object |
An object of class |
warn |
Logical scalar. See the help for |
drop |
Logical scalar. If there is a single sequence of observations
(i.e. if |
... |
Not used. |
The observation sequence(s) must be present in object
(which
will be the case if object
was returned by hmm()
and if the argument keep.y
was set to TRUE
).
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)
If the observations consist of a single sequence and if
drop
is TRUE
then the returned value consists
of a single object (matrix, list of two matrices, or 3-dimensional
array, depending on circumstances; see below). Otherwise the
returned value is a list of such objects, one for each observation
sequence.
If the observations are numeric then the object corresponding
to each observation sequence is a matrix. If the model is
univariate (see hmm()
) then matrix has a single
column constituting the sequence of fitted values corresponding to
the observations in the given sequence. The number of rows is the
number of observations and the entry in row t
is the fitted
value (conditional expection) corresponding to the observation made
at time t
. 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 are categorical then the nature of the object
returned changes substantially depending on whether the data are
univariate, bivariate independent or bivariate dependent. (See
hmm()
.
In the unvariate case the object corresponding to each sequence
is a matrix, the number of rows of which is the number of
observations and the number of columns of which is the number of
unique possible values of the observations. The entry of
this matrix in row t
and column j
is the conditional
probability that an emission, at time t
, is equal to
u[i] where u[1], …, u[m]
are the unique possible values.
In the bivariate independent case the object is a list of two matrices, each of which is of the same nature as that produced in the univariate case, corresponding respectively to the first and second of the two variables.
In the bivariate dependent case the object is a 3-dimensional
array of dimension m1 x m2 x n
where m1 is the number of unique possible values
of the first variable, m2 is the number of unique
possible values of the second variable, and n is the number
of observations. The (i,j,t)-th
entry of this array is
the conditional probability that an emission, at time t
,
is equal to (u[i],v[j]) where the u[i]
are the unique possible values of the first variable and the
v[j] are the unique possible values of the second
variable.
Rolf Turner
r.turner@auckland.ac.nz
sp()
link{predict.hmm.discnp}()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.