hmm.discnp (version 0.1-7)

logLikHmm: Log likelihood of a hidden Markov model

Description

Calculate the log likelihood of a hidden Markov model with discrete non-parametric observation distributions.

Usage

logLikHmm(y, par)

Arguments

y
A sequence, or list of sequences, of observations from a hidden Markov model with discrete non-parametric observation distributions.
par
A list with entries
  • Rho: The matrix whose columns consist of the probabilities specifying the distributions of the observations.
  • tpm: The transition probability matrix of the Markov chain.
  • (Optionally)

Value

  • The loglikehood of y given the parameter values specified in par.

Details

The observation values (the entries of y, or of the sequences which constitute the entries of y if y is a list) must be members of the set of row names of Rho. More specifically, if Rho has no row names then these observation values must all be integers between 1 and nrow(Rho). If Rho has row names then these observations must be character strings and must be members of row.names(Rho).

References

See hmm() for references.

See Also

hmm(), pr(), sp()

Examples

Run this code
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.num <- sim.hmm(lll,P,R)
y.let <- sim.hmm(lll,P,R,yval=letters[1:5])
ll1 <- logLikHmm(y.num,list(tpm=P,Rho=R))
row.names(R) <- letters[1:5]
ll2 <- logLikHmm(y.let,list(tpm=P,Rho=R))
# Note: ll2 differs from ll1 since y.num and y.let were
# simulated from different random seeds.
ll3 <- logLikHmm(y.let,list(tpm=P,Rho=R,ispd=c(0.5,0.5)))
fit <- hmm(y.num,K=2)
ll4 <- logLikHmm(y.num,fit) # Use the fitted rather than the "true" parameters.

Run the code above in your browser using DataLab