logLikHmm {hmm.discnp} | R Documentation |
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 one or two column matrix or 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 |
tpm |
The transition probability matrix of the Markov chain.
Ignored (and extracted from |
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 |
Rho |
An object specifying the “emission” probabilities
of the observations. (See the Details in the help for
|
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. If |
addIntercept |
Logical scalar. See the documentation of |
warn |
Logical scalar; should a warning be issued if |
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)
.
Value
The loglikehood of y
given the parameter values specified
in par
.
Author(s)
Rolf Turner
r.turner@auckland.ac.nz
References
See hmm()
for references.
See Also
Examples
# 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)
set.seed(909)
y.num <- rhmm(ylengths=lll,nsim=1,tpm=P,Rho=R,drop=TRUE)
set.seed(909)
y.let <- rhmm(ylengths=lll,nsim=1,tpm=P,Rho=R,yval=letters[1:5],drop=TRUE)
row.names(R) <- 1:5
ll1 <- logLikHmm(y.num,tpm=P,Rho=R)
row.names(R) <- letters[1:5]
ll2 <- logLikHmm(y.let,tpm=P,Rho=R)
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.