Skip to content

Support for non-homogeneous hidden Markov models #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 244 commits into from
Mar 31, 2025
Merged

Support for non-homogeneous hidden Markov models #69

merged 244 commits into from
Mar 31, 2025

Conversation

helske
Copy link
Owner

@helske helske commented Mar 31, 2025

This is a major update to seqHMM. New models of class nhmm, mnhmm, and fanhmm (inheriting from nhmm) support covariates in initial, transition and emission probabilities. In addition, visualizations are now based on ggplot2 graphics (with the help of ggseqplot), and post-estimation functions such as posterior_probs return data frames (data.table actually).

From NEWS:

  • Added support for non-homogeneous HMMs (NHMMs) where initial, transition, and emission probabilities can depend on individual-specific covariates. For mixture NHMMs cluster probabilities can also depend on covariates.
  • Added support for feedback-augmented NHMMs where responses and states can depend also on the past responses.
  • Added bootstrap_coef bootstrapping coefficients of NHMMs.
  • Added a function predict, which can be used to compute average marginal predictions for NHMMs, which can be interpreted as average causal effects under suitable assumptions (https://arxiv.org/abs/2503.16014).
  • Added get_* functions for obtaining initial, transition, emission and cluster probabilities and their (conditional) marginals.
  • Rewrote all post-estimation functions such as hidden_paths and forward_backward so that they return data.table.
  • Added functions stslist_to_data and data_to_stslist to convert between data frames and TraMineR's stslist objects (created by seqdef).
  • Rewrote sequence visualization functions using ggseqplot and patchwork packages. Old plotting functions are deprecated and will be removed in the future.
  • Warning and error messages were rewritten using cli package.
  • Removed the function estimate_coef. A portion of the code was accidentally commented out, rendering the function non-functional for several years. Rather than correcting the code, the function was removed as it was deemed unnecessary.
  • Added automatic tests using testthat package.
  • Internally switched from Rd syntax to Markdown in Roxygen documentation.

Some things are still missing, at least:

  • More examples and detailed documentation of new features.
  • Automatic visualization of the time-varying transitions and emissions, maybe also coefficients.
  • Compared to old hmm, new models do not support constraints in emission or transition matrices. These are tricky in general, but we could have separate model class for left-to-right models as well as pure (mixture) Markov models.
  • FAN-HMMs as whole (and maybe some functions for other NHMMs as well) do not yet support multichannel responses.

Jouni Helske and others added 26 commits January 20, 2025 13:14
@helske helske requested a review from Copilot March 31, 2025 12:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces support for non-homogeneous HMMs by adding new model classes and updating visualization, post‑estimation functions, and testing workflows.

  • Updated NEWS.md to document new NHMM and related model features
  • Modified GitHub Actions workflows to add branch filters for “nhmm” and update action versions and environment variables
  • Improved coverage tests with additional package dependencies and configuration adjustments

Reviewed Changes

Copilot reviewed 301 out of 318 changed files in this pull request and generated no comments.

File Description
NEWS.md Added release notes for seqHMM 2.0.0 with detailed bullet points summarizing new features
.github/workflows/test-coverage.yaml Updated branch filters, action versions, additional dependencies, and test coverage steps
.github/workflows/R-CMD-check.yaml Adjusted branch filters and environment variables; still uses an older checkout version compared to test-coverage
Files not reviewed (17)
  • .Rbuildignore: Language not supported
  • .covrignore: Language not supported
  • DESCRIPTION: Language not supported
  • Examples/mixhmmexample.R: Language not supported
  • Examples/seqHMMexample.R: Language not supported
  • NAMESPACE: Language not supported
  • R/HMMplot.R: Language not supported
  • R/RcppExports.R: Language not supported
  • R/SSPlotter-deprecated.R: Language not supported
  • R/biofam3c.R: Language not supported
  • R/bootstrap.R: Language not supported
  • R/build_fanhmm.R: Language not supported
  • R/build_hmm.R: Language not supported
  • R/build_lcm.R: Language not supported
  • R/build_mm.R: Language not supported
  • R/build_mmm.R: Language not supported
  • R/build_mnhmm.R: Language not supported
Comments suppressed due to low confidence (1)

.github/workflows/R-CMD-check.yaml:36

  • [nitpick] For consistency with the test-coverage workflow which uses actions/checkout@v4, consider updating the checkout action to v4 in this file.
- uses: actions/checkout@v3

@helske helske merged commit 1393379 into main Mar 31, 2025
12 checks passed
@helske helske deleted the nhmm branch March 31, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants