hmm.discnp (version 0.2-4)

sp: 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. Also can return the fitted conditional means, if requested, given that the observations are numeric.

Usage

sp(y, object = NULL, tpm, Rho, ispd=NULL, means = FALSE)

Arguments

y

The observations on the basis of which the probabilities of the underlying hidden states are to be calculated. May be a sequence of observations, or a list each component of which constitutes a (replicate) sequence of observations. If y is missing it is set equal to the y component of object, given that that object and that component exist. Otherwise an error is given.

object

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

tpm

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

Rho

The matrix of probabilities specifying the distribution of the observations, given the underlying state. The rows of this matrix correspond to the possible values of the observations, the columns to the states. Ignored if object is not NULL (in which case Rho is extracted from object).

ispd

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

means

A logical scalar; if means is TRUE then the conditional expected value of the observations (given the observation sequence) is calculated at each time point. If means is TRUE and the observation values are not numeric, then an error is given.

Value

If means is TRUE then the returned value is a list with components

probs

The conditional probabilities of the states at each time point.

means

The conditional expectations of the observations at each time point.

Otherwise the returned value consists of probs as described above.

If there is a single vector of observations y then probs is a matrix whose rows correspond to the states of the hidden Markov chain, and whose columns correspond to the observation times. If the observations consist of a list of observation vectors, then probs is a list of such matrices, one for each vector of observations.

Likewise for the means component of the list returned when the argument means is TRUE.

Details

Then conditional mean value at time \(t\) is calculated as $$\sum_k \gamma_t(k) \mu_k$$ where \(\gamma_t(k)\) is the conditional probability (given the observations) that the hidden Markov chain is in state \(k\) at time \(t\), and \(\mu_k\) is the expected value of an observation given that the chain is in state \(k\).

See Also

hmm(), mps(), viterbi(), pr(), fitted.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)
y.num   <- sim.hmm(rep(300,20),P,R)
fit.num <- hmm(y.num,K=2,verb=TRUE)
cpe1    <- sp(object=fit.num,means=TRUE)    # Using the estimated parameters.
cpe2    <- sp(y.num,tpm=P,Rho=R,means=TRUE) # Using the ``true'' parameters.
# }

Run the code above in your browser using DataLab