Learn R Programming

seqHMM: Hidden Markov Models for Life Sequences and Other Multivariate, Multichannel Categorical Time Series

The seqHMM package is designed for fitting hidden (latent) Markov models (HMMs) and their variations for social sequence data and other categorical sequence data (e.g. categorical time series and panel data). Restricted and extended variants include mixture HMMs, Markov models and their mixtures, latent class models, non-homogeneous hidden Markov models (NHMMs) and their mixtures, and feedback-augmented hidden Markov models (FAN-HMMs).

The package supports models for one or multiple subjects with one or multiple parallel outcome sequences (channels). External covariates can be added to explain cluster membership in mixture models, and NHMMs and their variants support covariates in initial, transition and emission matrices as well.

Maximum likelihood estimation via EM algorithm and direct numerical maximization with analytical gradients is supported. All main algorithms are written in C++. Parallel computation is available via OpenMP (pre-2.0.0 version models) and future (via parallel multistart estimation with random initial values).

When using the package in publications, please cite:

Helske, Satu and Helske, Jouni (2019). Mixture hidden Markov models for sequence data: the seqHMM package in R. Journal of Statistical Software, 88(3). doi:10.18637/jss.v088.i03.

Helske, Jouni (2025). Feedback-augmented Non-homogeneous Hidden Markov Models for Longitudinal Causal Inference. arXiv preprint. doi:10.48550/arXiv.2503.16014.

If you find bugs, please add a new issue here in GitHub. You can also contact Satu Helske (firstname.lastname@utu.fi) or Jouni Helske (firstname.lastname@iki.fi). We would be happy to hear your feedback.

The package is available on CRAN. Install it via

install.packages("seqHMM")

If you want to try the development version of the seqHMM package, install it from the R-universe:

install.packages("seqHMM", repos = "https://helske.r-universe.dev")

Copy Link

Version

Install

install.packages('seqHMM')

Monthly Downloads

2,601

Version

2.1.0

License

GPL (>= 2)

Maintainer

Jouni Helske

Last Published

September 25th, 2025

Functions in seqHMM (2.1.0)

colorpalette

Color palettes
fit_model

Estimate Parameters of (Mixture) Hidden Markov Models and Their Restricted Variants
get_emission_probs

Extract the Emission Probabilities of Hidden Markov Model
get_marginals

Compute the Marginal Probabilities from NHMMs
estimate_nhmm

Estimate a Non-homogeneous Hidden Markov Model
estimate_mnhmm

Estimate a Mixture Non-homogeneous Hidden Markov Model
mc_to_sc_data

Merge Multiple Sequence Objects into One (from Multichannel to Single Channel Data)
gridplot

Plot Multidimensional Sequence Plots in a Grid
hmm_biofam

Hidden Markov model for the biofam data
mc_to_sc

Transform a Multichannel Hidden Markov Model into a Single Channel Representation
get_initial_probs

Extract the Initial State Probabilities of Hidden Markov Model
logLik.nhmm

Log-likelihood of a Non-homogeneous Hidden Markov Model
logLik.hmm

Log-likelihood of a Hidden Markov Model
hidden_paths

Most Probable Paths of Hidden States
hmm_mvad

Hidden Markov model for the mvad data
leaves

Synthetic data on fathers' parental leaves in Finland
plot.ssp

Stack Multichannel Sequence Plots and/or Most Probable Paths Plots from Hidden Markov Models
mhmm_biofam

Mixture hidden Markov model for the biofam data
mssplot

Interactive Stacked Plots of Multichannel Sequences and/or Most Probable Paths for Mixture Hidden Markov Models
plot_colors

Plot Colorpalettes
most_probable_cluster

Extract Most Probable Cluster for Each Sequence
permute_states

Permute the states of NHMM using Hungarian algorithm
seqHMM-deprecated

Deprecated function(s) in the seqHMM package
plot.mhmm

Interactive Plotting for Mixed Hidden Markov Model (mhmm)
print.hmm

Print Method for a Hidden Markov Model
separate_mhmm

Reorganize a mixture hidden Markov model to a list of separate hidden Markov models (covariates ignored)
plot.hmm

Plot hidden Markov models
predict.nhmm

Predictions from Non-homogeneous Hidden Markov Models
nobs.hmm

Number of Observations in Hidden Markov Model
posterior_cluster_probabilities

Extract Posterior Cluster Probabilities
seqHMM-package

The seqHMM package
mhmm_mvad

Mixture hidden Markov model for the mvad data
return_msg

Convert return code from estimate_nhmm and estimate_mnhmm to text
posterior_probs

Posterior Probabilities for Hidden Markov Models
reexports

Objects exported from other packages
simulate_nhmm

Simulate Non-homogeneous Hidden Markov Models
state_names

Get State Names of Hidden Markov Model
simulate_initial_probs

Simulate Parameters of Hidden Markov Models
summary.mhmm

Summary method for mixture hidden Markov models
sort_sequences

Sort sequences in a sequence object
simulate_mhmm

Simulate Mixture Hidden Markov Models
simulate_mnhmm

Simulate Mixture Non-homogeneous Hidden Markov Models
simulate_hmm

Simulate hidden Markov models
ssplot

Stacked Plots of Multichannel Sequences and/or Most Probable Paths from Hidden Markov Models
ssp

Define Arguments for Plotting Multichannel Sequences and/or Most Probable Paths from Hidden Markov Models
get_transition_probs

Extract the State Transition Probabilities of Hidden Markov Model
summary.mnhmm

Summary method for mixture non-homogenous hidden Markov models
stacked_sequence_plot

Stacked Sequence Plots of Multichannel Sequences and/or Most Probable Paths from Hidden Markov Models
vcov.mhmm

Variance-Covariance Matrix for Coefficients of Covariates of Mixture Hidden Markov Model
update.nhmm

Update Covariate Values of NHMM
trim_model

Trim Small Probabilities of Hidden Markov Model
cluster_names

Get Cluster Names from Mixture HMMs
build_mhmm

Build a Mixture Hidden Markov Model
build_hmm

Build a Hidden Markov Model
bootstrap_coefs

Bootstrap Sampling of NHMM Coefficients
get_cluster_probs

Extract the Prior Cluster Probabilities of MHMM or MNHMM
build_mmm

Build a Mixture Markov Model
build_lcm

Build a Latent Class Model
cluster_names<-

Set Cluster Names for Mixture Models
build_mm

Build a Markov Model
biofam3c

Three-channel biofam data
coef.nhmm

Get the Estimated Regression Coefficients of Non-Homogeneous Hidden Markov Models
forward_backward

Forward and Backward Probabilities for Hidden Markov Model
data_to_stslist

Transform TraMineR's state sequence object to data.table and vice versa
fanhmm_leaves

A feedback-augmented non-homogeneous hidden Markov Model for leaves data