hmm.discnp (version 2.1-5)

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, model=NULL, tpm=NULL, ispd=NULL, Rho=NULL, X=NULL,
          addIntercept=NULL, warn=TRUE)

Arguments

y

A vector, or list of vectors, or a two column matrix or a a list of such matrics, whose entries consist of observations from a hidden Markov model with discrete non-parametric observation distributions.

model

An object specifying a hidden Markov model, usually returned by hmm().

tpm

The transition probability matrix of the Markov chain. Ignored (and extracted from model) if model is non-NULL.

ispd

The vector of probabilities specifying the initial state probability distribution, or a matrix each of whose columns is a trivial (“delta function”) vector specifying the “most probable” initial state for each observation sequence. If ispd is missing then ispd is calculated as the stationary distribution determined by tpm. Ignored (and extracted from model) if model is non-NULL.

Rho

An object specifying the “emission” probabilities of the observations. (See the Details in the help for hmm().) Ignored (and extracted from model) if model is non-NULL.

X

An optional numeric matrix, or a list of such matrices, of predictors. The use of such predictors is (currently, at least) applicable only in the univariate emissions setting, and then only if Rho is supplied in the “newstyle” format. 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(). If this argument is not specified, and if model is NULL then an error is thrown.

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.

Value

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

Details

If y is not provided the function simply returns the log.like component of model (which could be NULL if model was not produced by hmm().

The observation values (the entries of the vector or matrix y, or of the vectors or matrices which constitute the entries of y if y is a list) must be consistent with the appropriate dimension names of Rho or of its entries when Rho is a list. More specifically, if Rho has dimension names (or its entries have dimension names) then the observation values must all be found as entries of the appropriate dimension name vector. If a vector of dimension names is NULL then the corresponding dimension must be equal to the number of unique observations of the appropriate variate. integers between 1 and nrow(Rho).

References

See hmm() for references.

See Also

hmm(), pr(), sp()

Examples

Run this code
# NOT RUN {
# TO DO:  One or more bivariate 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)
lll   <- sample(250:350,20,TRUE)
y.num <- rhmm(ylengths=lll,nsim=1,tpm=P,Rho=R,drop=TRUE)
y.let <- rhmm(ylengths=lll,nsim=1,tpm=P,Rho=R,yval=letters[1:5],drop=TRUE)
ll1   <- logLikHmm(y.num,tpm=P,Rho=R,warn=FALSE)
row.names(R) <- letters[1:5]
ll2   <- logLikHmm(y.let,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,tpm=P,Rho=R,ispd=c(0.5,0.5))
fit   <- hmm(y.num,K=2,itmax=10)
ll4   <- logLikHmm(y.num,fit) # Use the fitted rather than the "true" parameters.
# }

Run the code above in your browser using DataLab