reorder.eglhmm {eglhmm} | R Documentation |
Reorder the states of a fitted eglhmm model
Description
Reorder the states of a fitted eglhmm model so that the state effects are in decreasing order.
Usage
## S3 method for class 'eglhmm'
reorder(x, ...)
Arguments
x |
An object of class |
... |
Not used. |
Details
The states of a fitted hidden Markov model are usually in a
rather arbitrary order, which can sometimes make it difficult
to compare different fits. This function reorders the states
so that the state corresponding to the “largest state
effect” comes first (and so on down the line). What is meant by
“largest state effect” depends on whether the distribution
used in the model is “Dbd”. If the distribution is
not “Dbd”, then what is meant is simply the largest
of those entries of phi
which correspond to state
.
(The vector phi
is the vector of coefficients of the
linear predictor in the model. Note that, since the formula
for the model is constructed as y~0+state+...
, the
“state” coefficients are unconstrained and there are as
many of them as there are states.)
If the distribution in question is “Dbd” then things
are a bit more complicated. We calculate the theoretical expected
values for “Dbd”s with parameters \alpha =
alpha[k]
and \beta =
beta[k]
where
alpha[k]
and beta[k]
are the parameter values
corresponding to the k
th state. The states are then
ordered according to the decreasing order of these expected
values. These expected values are the expected values of the
emissions given that all predictors other than the state
predictors are zero.
Value
An object of class c("eglhmm","reordered")
which
is identical to the argument x
in most respects.
The components which (may) differ are:
-
tpm
-
ispd
-
phi
-
theta
-
Hessian
-
gradient
-
mean
andsd
, orlambda
orp
, oralpha
andbeta
(depending on which distribution is being used) -
fy
The entries of these components will have the same numerical values as before but, given that the ordering of the states has actually changed, will have different orderings, corresponding to the new ordering of the states.
Note that the attribute preSpecSigma
of the
component theta
, may differ from what it was in x
.
The returned value will also have a component neworder
which is an integer vector providing the indices of the
reordering of the states. It also currently (13/02/2024) has a
component newlog.like
. This should (if there is any
justice in the world — but there isn't!) have the same value
as the component log.like
. Once I am confident that
everything is working as it should, the newlog.like
component will be removed.
Author(s)
Rolf Turner rolfturner@posteo.net
See Also
eglhmm()
Examples
loc4 <- c("LngRf","BondiE","BondiOff","MlbrOff")
SCC4 <- SydColCount[SydColCount$locn %in% loc4,]
SCC4$locn <- factor(SCC4$locn) # Get rid of unused levels.
rownames(SCC4) <- 1:nrow(SCC4)
fit <- eglhmm(y~locn+depth,data=SCC4,cells=c("locn","depth"),
K=2,distr="P",verb=TRUE)
ofit <- reorder(fit)