Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

hmm

Fit hidden Markov and latent class models.


Description

hmm fits a hidden Markov model to its first argument. lca fits a latent class model or mixture model to its first argument.

Both functions provide an easy user-interface to the functions provided in depmixS4 by automagically setting some argument values.

Usage

hmm(data, nstates, fit = TRUE, ntimes = NULL, family = NULL, verbose=FALSE, ...)
lca(data, nclasses, fit = TRUE, family = NULL, verbose=FALSE, ...)

Arguments

data

(columns of) a data.frame or matrix like object.

nstates

the required number of states of the hidden Markov model.

nclasses

the required number of classes of the mixture or latent class model.

fit

logical indicating whether the model needs to be fitted or returned unfitted; the latter is necessary if one wants to set constraints on the parameters, which then requires using the fit function from depmixS4.

ntimes

the lengths of time series in argument data; it defaults to assuming a single time series of length nrow(data).

family

(a list of) name(s) of the distribution(s) to be used in fitting; if provided, it should have length of the number of the number of columns in data, see Details.

verbose

logical; when TRUE iteration information of the fitting process is printed.

...

not currently used.

Details

The distributions used in fitting models are the multinomial for factor data columns and gaussian for numeric data columns. Data columns are treated as conditionally independent variables. Use makeDepmix in the depmixS4 package to specify multivariate distributions.

Value

hmm returns a depmix or depmix.fitted object depending on the value of the fit argument; lca similarly returns either a mix or mix.fitted object.

All these can be print'ed and summary'zed.

Author(s)

Ingmar Visser

References

Visser, I., & Speekenbrink, M. (2010). depmixS4: an R-package for hidden Markov models. Journal of Statistical Software, 36(7), 1-21.

Examples

data(conservation)

set.seed(1)
m2 <- lca(conservation$"r1", nclasses=2)
m2
summary(m2)

data(speed1)

set.seed(1)
hm2 <- hmm(speed1$"RT", nstates=2)
hm2
summary(hm2)

hmmr

"Mixture and Hidden Markov Models with R" Datasets and Example Code

v1.0-0
GPL (>= 2)
Authors
Ingmar Visser [aut, cre], Maarten Speekenbrink [aut]
Initial release
2021-05-26

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.