Source-linked AI summary

Mixture Hidden Markov Models for Sequence Data: The seqHMM Package in R

Satu Helske, Jouni Helske

arXiv:1704.00543v2stat.COstat.AP

TL;DR

Large multichannel sequence data can be difficult to describe, compare, and visualize. The paper presents seqHMM, an R package for modeling categorical sequences with HMMs and MHMMs and visualizing data and models; it supports a range of model variants and includes options for multichannel sequence plots.

  • Problem

    Describing, visualizing, and comparing large sequence data is complex, especially when subjects have multiple interdependent sequences.

    Source: §1 · p. 1
  • Method

    seqHMM models categorical sequence data with HMMs and MHMMs, supports restricted model variants, and provides plotting options for sequences and models.

    Source: §5 · p. 27
  • Results

    The package handles data from single sequences to multiple multichannel sequences and allows covariates to explain MHMM cluster membership.

    Source: §5 · p. 27
  • Takeaways & Limitations

    The package offers tools spanning data preparation and description through model fitting, evaluation, and visualization, especially alongside TraMineR.

    Source: §5 · p. 29

    The package does not yet support time-varying covariates in MHMM transition and emission matrices or sampling weights for model estimation.

    Source: §5 · p. 29

Abstract

from arXiv · show

Sequence analysis is being more and more widely used for the analysis of social sequences and other multivariate categorical time series data. However, it is often complex to describe, visualize, and compare large sequence data, especially when there are multiple parallel sequences per subject. Hidden (latent) Markov models (HMMs) are able to detect underlying latent structures and they can be used in various longitudinal settings: to account for measurement error, to detect unobservable states, or to compress information across several types of observations. Extending to mixture hidden Markov models (MHMMs) allows clustering data into homogeneous subsets, with or without external covariates. The seqHMM package in R is designed for the efficient modeling of sequences and other categorical time series data containing one or multiple subjects with one or multiple interdependent sequences using HMMs and MHMMs. Also other restricted variants of the MHMM can be fitted, e.g., latent class models, Markov models, mixture Markov models, or even ordinary multinomial regression models with suitable parameterization of the HMM. Good graphical presentations of data and models are useful during the whole analysis process from the first glimpse at the data to model fitting and presentation of results. The package provides easy options for plotting parallel sequence data, and proposes visualizing HMMs as directed graphs.

1. Introduction

Large sequence data can be difficult to describe, visualize, and compare, especially when subjects have multiple interdependent sequences. The introduction presents seqHMM as an R package for modeling such data and visualizing sequences and models.

1. Introduction

  • HMMs detect underlying latent structures, while mixture HMMs allow clustering into latent classes, potentially using covariates.The paper frames both as probabilistic approaches to analyzing sequence data.Source: §1 · pp. 1–2
  • seqHMM provides R functions for estimating and inferring HMMs and MHMMs, and for visualizing multichannel sequences and models.The package is intended for one or multiple subjects and one or multiple channels.Source: §1 · p. 2
  • Existing R packages cover different settings; seqHMM's MHMMs allow emission probabilities to vary between groups and covariates to explain group membership.The introduction contrasts this with LMest's mixed latent Markov models, where the latent process varies across subpopulations.Source: §1 · p. 2
  • The paper proceeds from sequence data and HMM/MHMM theory to visualization, package features, and a life-course data example.It also outlines special model cases and an appendix of notation.Source: §1 · p. 2

2. Methods

The methods define categorical sequence data and HMMs, then extend them to multiple subjects, interdependent channels, and latent-class mixtures. They also describe estimation, inference, model comparison, and special cases supported by seqHMM.

2.1. Sequences and sequence analysis

  • Sequences are ordered categorical states; social sequence analysis describes successions, computes sequence (dis)similarities, and often uses clustering to find trajectory patterns.Source: §2.1 · p. 3

2.2. Hidden Markov models

  • HMMs represent observations as probabilistic emissions from hidden states, with time-homogeneous first-order transitions and observations conditionally dependent on the current hidden state.Source: §2.2 · pp. 3–4

HMM for multichannel sequences

  • For multichannel data, seqHMM uses one shared latent structure, a transition matrix, and channel-specific emission matrices, assuming channel observations are conditionally independent given the hidden state.Source: HMM for multichannel sequences · pp. 4–5
  • Multichannel modeling can retain partially observed channels without combining missing and observed values into a potentially larger, harder-to-interpret state space.Source: HMM for multichannel sequences · p. 5

Log-likelihood and parameter estimation

  • Parameters are estimated by maximum likelihood using direct numerical maximization or EM; forward–backward calculations support likelihoods and inference, while many starting values reduce local-maximum risk.Source: Log-likelihood and parameter estimation · pp. 5–6

Inference on hidden states

  • Posterior state probabilities give time-specific hidden-state probabilities, whereas the Viterbi algorithm finds the single most probable hidden-state sequence.Source: Inference on hidden states · p. 6

2.3. Clustering by mixture hidden Markov models

Mixture hidden Markov model

3. Package features

seqHMM provides tools for sequence-data manipulation, description, model building, evaluation, and visualization. It extends TraMineR with multichannel plotting and conversion tools, alongside functions for fitting and presenting HMMs and related models.

3. Package features

  • seqHMM uses TraMineR’s stslist objects and extends its sequence-analysis features with multichannel plotting and conversion to a single-channel representation.TraMineR supplies sequence construction, summarization, visualization, and data-manipulation features used by seqHMM.Source: §3 · p. 10
  • The package covers HMM and MHMM estimation and evaluation, data and model manipulation, visualization, and simulation.Table 1 catalogs the available functions and methods.Source: §3 · p. 10

3.1. Building and fitting models

  • Build functions cover HMMs, MHMMs, Markov models, mixture Markov models, and latent class models; zero probabilities are fixed, and covariates must be complete.Users may supply starting values or use random ones; ordinary Markov models receive estimated initial and transition probabilities automatically.Source: §3.1 · p. 11
  • Fitting can combine EM, global DNM, and local DNM in that order, with each step generally initializing the next.The package implements EM and gradient calculations in C++ with optional parallel computation between subjects; multiple randomized EM starts and global methods offer alternative searches.Source: §3.1 · pp. 11–12
  • No optimization method is universally best: larger unconstrained models increase computation time and the risk of local optima or saddle points, so several settings are advisable.The authors report most success with randomized EM and suggest comparing different optimization strategies.Source: §3.1 · p. 12

State and model inference

  • Inference tools compute forward–backward probabilities, posterior probabilities, and most probable hidden paths, while log-likelihood output supports AIC and BIC.MHMM, mixture Markov, and latent class summaries include covariate standard errors and prior and posterior cluster probabilities.Source: State and model inference · pp. 12–13

3.2. Visualizing sequence data

  • Stacked sequence plots align channels by subject; ssplot defaults to state distributions and also supports sequence index plots, while gridplot combines views or groups.Grid layouts are configurable, and sequences can be ordered using multidimensional scaling scores based on sequence dissimilarities.Source: §3.2 · pp. 13–14

3.3. Visualizing hidden Markov models

  • Directed HMM graphs encode hidden states as pie-chart nodes, emissions as slices, transitions as edges, and initial probabilities beside nodes; MHMM plots can show clusters separately or together.The ssplot method can also display observations, most probable hidden paths, or both; mssplot provides stacked plots by cluster.Source: §3.3 · pp. 14, 16

4. Examples with life course data

The examples use life-course data to demonstrate sequence construction and visualization, including plots of state distributions and complete sequences. They also show how parallel channels can be displayed together.

4. Examples with life course data

  • The examples progress from constructing sequence data to visualizing it, fitting single- and multichannel HMMs, clustering with MHMMs, and plotting models.Source: §4 · p. 16

4.1. Sequence data

  • The examples use the original biofam data and a three-channel version, defining sequence start ages, state labels, and channel colors for plotting.Source: §4 · p. 16, §4.1 · p. 18

Figure 2: Plotting state distributions

Figure 1: Plotting sequences

Figure 3: Plotting sequence data in a grid

The examples demonstrate arranging sequence plots in a grid and fitting HMMs to single- and multichannel life-course data. They illustrate alternative initialization and fitting choices.

Figure 3: Plotting sequence data in a grid

4.2. Hidden Markov models

  • The examples use build_hmm to initialize models and fit_model to estimate parameters; the fitting output includes the estimated model, log-likelihood, and optimization information.Source: §4.2 · pp. 20–21
  • For a single-channel HMM, starting probabilities can be initialized from observed state frequencies across age groups, with zero-frequency categories smoothed by adding 0.1 before row normalization.Source: §4.2 · p. 20
  • The multichannel example fits a five-state left-to-right model with separate emission matrices per channel and an upper-triangular transition matrix, then estimates parameters using L-BFGS with four threads.Source: §4.2 · p. 22

4.3. Clustering and mixture hidden Markov models

The example fits a two-cluster multichannel MHMM using sex and birth cohort as membership covariates. Its output includes covariate estimates, model-fit statistics, and mean prior cluster probabilities.

  • The example specifies two clusters with five and four hidden states, uses sex and birth cohort to explain membership, and follows 100 EM restarts with local L-BFGS fitting.Source: §4.3 · p. 23
  • The MHMM summary reports covariate estimates and standard errors, log-likelihood and BIC, and cluster probabilities; its classification table gives mean probabilities by most probable cluster.Source: §4.3 · p. 24
  • The reported fit has log-likelihood -12969.57 and BIC 26592.66; mean prior cluster probabilities are 0.857 for Cluster 1 and 0.143 for Cluster 2.Source: §4.3 · p. 24

4.4. Visualizing hidden Markov models

The examples use a default plot method to visualize an HMM as a graph. The paper notes that publication figures may benefit from modifying the default presentation.

  • A basic HMM graph can be drawn with the plot method; the default view is convenient during analysis, while publication may call for a tailored presentation.Source: §4.4 · p. 25

Figure 4: HMM plot with modifications

The examples show how seqHMM plotting can be customized for HMM layouts and colors, and how observed and hidden state sequences can be plotted from an HMM object.

Figure 4: HMM plot with modifications

Figure 5: HMM plot with a different layout

4.5. Visualizing mixture hidden Markov models

Mixture HMMs can be plotted as separate cluster models or as a combined graph, while data and hidden paths can be displayed by cluster. The section also describes options for arranging and customizing these views.

  • The default interactive plot displays each MHMM cluster model separately, while a combined plot can become difficult to fit with several graphs and legends.Source: §4.5 · p. 27
  • Setting interactive = FALSE and nrow = 2 arranges the cluster-model graphs in a two-row grid.Source: §4.5 · p. 27
  • The mssplot function shows data and/or hidden paths one cluster at a time, allocating subjects according to their most probable hidden state paths.Source: §4.5 · p. 27
  • For more control, separate_mhmm converts an MHMM into separate HMM objects that can be plotted with sequence and grid plotting functions.Source: §4.5 · p. 27

5. Conclusion

seqHMM supports categorical sequence analysis with HMMs, MHMMs, and restricted variants, alongside fitting and visualization tools. The paper identifies planned extensions and computational improvements, including time-varying covariates and sampling weights.

  • HMMs can account for observation measurement error, detect unobservable states, or compress information across observation types.Source: §5 · p. 27
  • seqHMM handles categorical data from single sequences to multichannel sequences, with HMMs, MHMMs, and restricted variants including Markov and latent class models.Covariates can explain cluster membership in MHMMs.Source: §5 · p. 27
  • Because parameter estimation is sensitive to starting values, seqHMM offers fitting options using global and local optimization, direct numerical estimation, and the EM algorithm.Source: §5 · p. 27
  • Almost all intensive computations use C++, and the package supports parallel computation.Source: §5 · p. 27
  • Planned work includes time-varying covariates in transition and emission matrices, sampling weights, and faster computations for restricted model variants.Source: §5 · p. 29

A. Notations

The notation defines observations and hidden states for subjects and channels, then specifies transition, emission, and initial-state probabilities. It also names the mixture-model quantities for clusters and covariates.

  • Y_i denotes subject i's observation sequences; y_it and y_itc denote observations at time t overall and in channel c, respectively.Source: A. Notations · p. 29
  • z_it is the hidden state at time t, and s ranges over the hidden-state space of size S.Source: A. Notations · p. 29
  • A gives transition probabilities between hidden states, B_c gives channel-specific emission probabilities, and π gives initial-state probabilities.Source: A. Notations · p. 29
  • In the mixture model, M_k denotes cluster k's submodel, w_ik its probability for subject i, and x_i the subject's covariates.The cluster-specific parameter set includes initial probabilities, transition and emission matrices, and regression coefficients.Source: A. Notations · p. 29
Loading 1704.00543v2…