pr {hmm.discnp} | R Documentation |
Probability of state sequences.
Description
Calculates the conditional probability of one or more state sequences, given the corresponding observations sequences (and the model parameters.
Usage
pr(s, y, model=NULL, tpm, Rho, ispd=NULL, warn=TRUE)
Arguments
s |
A sequence of states of the underlying Markov chain, or a list of such sequences or a list of lists (!!!) of such sequences. |
y |
A data set to which a hidden Markov model might be fitted,
or a collection of such data sets in the form of an object
of class If |
model |
An object of class |
tpm |
The transition probability matrix of the chain. Ignored (and
extracted from |
Rho |
An object specifying the “emission” probabilities of
observations, given the underlying state. See |
ispd |
The vector specifying the initial state probability distribution
of the Markov chain. Ignored (and extracted from |
warn |
Logical scalar; should a warning be issued if |
Value
The probability of s
given y
, or a vector of such
probabilities if s
and y
are lists, or a list of
such vectors if y
is of class "multipleHmmDataSets"
.
Warning
The conditional probabilities will be tiny if the sequences involved are of any substantial length. Underflow may be a problem. The implementation of the calculations is not sophisticated.
Author(s)
Rolf Turner
r.turner@auckland.ac.nz
See Also
hmm()
, mps()
,
viterbi()
, sp()
,
fitted.hmm.discnp()
Examples
## 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)
lll <- sample(250:350,20,TRUE)
set.seed(909)
y.num <- rhmm(ylengths=lll,nsim=1,tpm=P,Rho=R,drop=TRUE)
fit.num <- hmm(y.num,K=2,keep.y=TRUE,verb=TRUE)
# Using fitted parmeters.
s.vit.1 <- viterbi(y.num,fit.num)
pr.vit.1 <- pr(s.vit.1,model=fit.num)
# Using true parameters from which y.num was generated.
s.vit.2 <- viterbi(y.num,tpm=P,Rho=R)
pr.vit.2 <- pr(s.vit.2,y.num,tpm=P,Rho=R)
set.seed(202)
y.mult <- rhmm(fit.num,nsim=4)
s.vit.3 <- viterbi(y.mult,tpm=fit.num$tpm,Rho=fit.num$Rho)
pr.vit.3 <- pr(s.vit.3,y.mult,tpm=fit.num$tpm,Rho=fit.num$Rho)
## End(Not run)