Multilevel Hidden Markov Models Using Bayesian Estimation
Overview
An implementation of the multilevel (also known as mixed or random effects) hidden Markov model using Bayesian estimation in R. The multilevel hidden Markov model (HMM) is a generalization of the well-known hidden Markov model, for the latter see Rabiner (1989) doi:10.1109/5.18626. The multilevel HMM is tailored to accommodate (intense) longitudinal data of multiple individuals simultaneously, see e.g., de Haan-Rietdijk et al. doi:10.1080/00273171.2017.1370364. Using a multilevel framework, we allow for heterogeneity in the model parameters (transition probability matrix and conditional distribution), while estimating one overall HMM. The model can be fitted on multivariate data with either a categorical, normal, or Poisson distribution, and include individual level covariates (allowing for e.g., group comparisons on model parameters). Parameters are estimated using Bayesian estimation utilizing the forward-backward recursion within a hybrid Metropolis within Gibbs sampler. Missing data (NA) in the dependent variables is accommodated assuming MAR. The package also includes various visualization options, a function to simulate data, and a function to obtain the most likely hidden state sequence for each individual using the Viterbi algorithm.
Accomodating the possibility of fitting a 1-state mHMM
This version includes the possibility of running (and simulating data from) a 1-state multilevel hidden Markov model. This is mainly convenient for benchmarking purposes for model selection (e.g., how much does the AIC / AICc decrease from a 1-state to a 2-state model). To accommodate this change the following main functions are updated: mHMM() and sim_mHMM(). The following S3 methods were updated: print(), summary(), and plot(). In addition, the following post processing functions were updated: obtain_emiss(), obtain_gamma(), and vit_mHMM().
Other minor changes:
The estimation vignette is changed from a pdf output file to a html output file due to recurrent issues with GHA workflow and rendering pdf vignettes.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK14 OK2026-04-22
- ERROR13 OK, 1 ERROR2026-04-18
- OK14 OK2026-03-10
Documentation
- Help pages
- 20 (1 internal)includes a package overview page
- Examples that run
- 71%12 run in a plain check · 5 only when donttest examples are enabled (R CMD check --as-cran)
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 25% with a bibliography file
Downloads
Repository
- PRs merged (all time)
- 55%
- Median days to close, 50 most recently updated closed issues
- 324
- Median days to close, 50 most recently updated closed PRs
- 0
Stars over time
Forks over time
Releases over time
Issues over time
PRs over time
9 development-tooling and community-health practices detected across 5 families in the upstream repository
Checks run against github.com/emmekeaarts/mhmmbayes on 2026-10-22.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-04-17
Show all practicesHide 1 practice
An outside contributor's pull request to this repository was written with an AI coding tool.
- Claude CodePull requests: 1 from outside contributors, first on 2025-09-27, 1 from forks
Dependencies
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- RR 4.6.0 released · 2026-04-24
- 1.1.1Latest
- RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- 1.1.0
- 1.0.0
- RR 4.3.0 released · 2023-04-21
- 0.2.02022-08-17 · diff ↗ ·
added 6 exports
int_to_prob, pd_RW_emiss_cat, pd_RW_gamma, prior_emiss_cat, prior_gamma, prob_to_int - RR 4.2.0 released · 2022-04-22
- RR 4.1.0 released · 2021-05-18
- RR 4.0.0 released · 2020-04-24
- 0.1.12019-10-30 · diff ↗
- 0.1.02019-10-25
- RR 3.6.0 released · 2019-04-26
Package metadata
- First published
- 2019-10-25
- Total releases
- 6 / 7 yrs
- License
- GPL-3 OSI
- Minimum R
- ≥ 3.6.0
- Bundled data
- 4.0 KB / 2 files
- Download size
- 2.5 MB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("mHMMbayes")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-25, which the citation names so these numbers can be found later. More on citing and the projects behind them.