sp: Calculate the conditional state probabilities.

spR Documentation

Calculate the conditional state probabilities.

Description

Returns the probabilities that the underlying hidden state is equal to each of the possible state values, at each time point, given the observation sequence.

Usage

sp(y, model = NULL, tpm=NULL, Rho=NULL, ispd=NULL, X=NULL,
   addIntercept=NULL, warn=TRUE, drop=TRUE)

Arguments

y

The observations on the basis of which the probabilities of the underlying hidden states are to be calculated. May be a vector of a one or two column matrix of observations, or a list each component of which is such a vector or matrix. If y is missing it is set equal to the y component of model, given that that argument is non-NULL and that that component exists. Otherwise an error is given.

model

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

tpm

The transition probability matrix for the underlying hidden Markov chain. Ignored if model is not NULL (in which case tpm is extracted from model).

Rho

An object specifying the distribution of the observations, given the underlying state. I.e. the “emission” probabilities. See hmm(). Ignored if model is not NULL (in which case Rho is extracted from model).

ispd

Vector specifying the initial state probability distribution of the underlying hidden Markov chain. Ignored if model is not NULL (in which case ispd is extracted from model). If both model[["ispd"]] and ispd are NULL then ispd is calculated to be the stationary distribution of the chain as determined by tpm.

X

An optional numeric matrix, or a list of such matrices, of predictors. Ignored if model is not NULL (in which case X is extracted from model).

The use of such predictors is (currently, at least) applicable only in the univariate emissions setting. If X is a list it must be of the same length as y and all entries of this list must have the same number of columns. The number of rows of each entry must be equal to the length of the corresponding entry of y. If X is a matrix then y should be a vector or one-column matrix (or a list with a single entry equal to such).

addIntercept

Logical scalar. See the documentation of hmm(). Ignored if model is not NULL (in which case addIntercept is extracted from model).

warn

Logical scalar; should a warning be issued if Rho hasn't got relevant dimension names? (Note that if this is so, then the corresponding dimension names are formed from the sorted unique values of y or of the appropriate column(s) of y. And if this is so, then the user should be sure that the ordering of the entries of Rho corresponds properly to the the sorted unique values of y.) This argument is passed to the utility function check.yval() which actually issues the warning if warn=TRUE.

drop

Logical scalar. If y is a matrix, or a list of length 1, and if drop is FALSE then the returned value is a list whose sole entry is the matrix that would have been returned were drop equal to TRUE. The argument drop is ignored if y is a list of length greater than 1.

Details

Note that in contrast to predict.hmm.discnp(), components in model take precendence over individually supplied components (tpm, Rho, ispd, X and addIntercept).

Value

If y is a single matrix of observations or a list of length 1, and if drop is TRUE then the returned value is a matrix whose rows correspond to the states of the hidden Markov chain, and whose columns correspond to the observation times. Otherwise the returned value is a list of such matrices, one for each matrix of observations.

Author(s)

Rolf Turner r.turner@auckland.ac.nz

See Also

hmm(), mps(), viterbi(), pr(), 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)
y    <- rhmm(ylengths=rep(300,20),nsim=1,tpm=P,Rho=R,drop=TRUE)
fit  <- hmm(y,K=2,verb=TRUE,keep.y=TRUE,itmax=10)
cpe1 <- sp(model=fit) # Using the estimated parameters.
cpe2 <- sp(y,tpm=P,Rho=R,warn=FALSE) # Using the ``true'' parameters.
# The foregoing would issue a warning that Rho had no row names
# were it not for the fact that "warn" has been set to FALSE.

hmm.discnp documentation built on Sept. 26, 2022, 5:05 p.m.

Related to sp in hmm.discnp...