Skip to main content
QUICK REVIEW

[Paper Review] hmmTMB: hidden Markov models with flexible covariate effects in R

Théo Michelot|arXiv (Cornell University)|Nov 25, 2022
Bayesian Methods and Mixture ModelsComputer Science7 citations
TL;DR

This paper introduces the R package hmmTMB, which enables flexible hidden Markov models (HMMs) with covariate effects on both transition and observation parameters using penalized splines for non-linear effects and random effects for inter-individual heterogeneity. The key contribution is a computationally efficient, modular framework for complex HMMs with automatic smoothness selection and support for multivariate, continuous, discrete, and binary responses.

ABSTRACT

Hidden Markov models (HMMs) are widely applied in studies where a discrete-valued process of interest is observed indirectly. They have for example been used to model behaviour from human and animal tracking data, disease status from medical data, and financial market volatility from stock prices. The model has two main sets of parameters: transition probabilities, which drive the latent state process, and observation parameters, which characterise the state-dependent distributions of observed variables. One particularly useful extension of HMMs is the inclusion of covariates on those parameters, to investigate the drivers of state transitions or to implement Markov-switching regression models. We present the new R package hmmTMB for HMM analyses, with flexible covariate models in both the hidden state and observation parameters. In particular, non-linear effects are implemented using penalised splines, including multiple univariate and multivariate splines, with automatic smoothness selection. The package allows for various random effect formulations (including random intercepts and slopes), to capture between-group heterogeneity. hmmTMB can be applied to multivariate observations, and it accommodates various types of response data, including continuous (bounded or not), discrete, and binary variables. Parameter constraints can be used to implement non-standard dependence structures, such as semi-Markov, higher-order Markov, and autoregressive models. Here, we summarise the relevant statistical methodology, we describe the structure of the package, and we present an example analysis of animal tracking data to showcase the workflow of the package.

Motivation & Objective

  • To address the need for flexible modeling of covariate effects in hidden Markov models (HMMs), particularly non-linear relationships and inter-individual heterogeneity.
  • To extend standard HMMs by allowing covariates to influence both transition probabilities and observation distribution parameters.
  • To provide a computationally efficient and modular R package that supports complex model formulations including mixed-effects and semi-Markov structures.
  • To enable automatic smoothness selection in non-linear effects using penalized splines within a likelihood-based inference framework.
  • To support diverse response types (continuous, binary, discrete) and complex dependence structures via parameter constraints.

Proposed method

  • Uses a mixed linear predictor model with fixed and random effects to parameterize transition and observation parameters: $\eta = \mathbf{X}\bm{\alpha} + \mathbf{R}\bm{\beta}$, $\bm{\beta} \sim N(\mathbf{0}, \mathbf{Q})$.
  • Implements non-linear covariate effects using penalized splines (P-splines), including univariate and multivariate splines, with automatic smoothness selection via Laplace approximation.
  • Leverages the TMB (Template Model Builder) framework for fast computation of the marginal likelihood via Laplace approximation.
  • Supports various response distributions (Gaussian, binomial, Poisson, etc.) and allows parameter constraints to model non-Markovian processes (e.g., higher-order Markov, semi-Markov).
  • Provides tools for model fitting, inference, and visualization, including functions for plotting transition probabilities, state probabilities, and random effects with confidence intervals.
  • Uses the forward algorithm for likelihood evaluation and optimizes the likelihood numerically to estimate model parameters.

Experimental results

Research questions

  • RQ1How can HMMs be extended to model non-linear effects of covariates on transition and observation parameters?
  • RQ2What is the impact of inter-individual heterogeneity on state transition dynamics in longitudinal data?
  • RQ3Can penalized splines with automatic smoothness selection be effectively integrated into HMMs for flexible non-linear modeling?
  • RQ4How can complex dependence structures (e.g., semi-Markov, higher-order Markov) be implemented within a unified HMM framework?
  • RQ5What is the performance and reliability of Laplace approximation in complex HMMs with random effects and splines?

Key findings

  • The package successfully models the probability of transitioning from a 'travelling' to a 'foraging' state in petrels as a function of distance to central location, showing a sharp decline in transition probability beyond 1000 km.
  • The estimated standard deviation of individual-specific random intercepts for transition S3→S2 was 0.414, indicating substantial inter-individual variability in state transition behavior.
  • The model identified that the probability of being in the 'travelling' state decreased significantly with increasing distance from the central location, suggesting targeted foraging behavior.
  • Smoothed effects of distance on transition probabilities were estimated with 95% confidence bands, demonstrating the utility of penalized splines for flexible, data-driven modeling.
  • The random effect standard deviations for transition S2→S3 were 0.466 (intercept) and 0.123 (spline), indicating strong individual-level variation in this transition.
  • The package enables efficient inference on complex HMMs, including multivariate responses and parameter constraints, with computational performance suitable for real-world ecological and biomedical data.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.