Multichannel and Covariate-Dependent HMMs

knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(gp3sequences)

Scope and guardrails

Multichannel HMMs model several categorical observation channels through a shared finite-state process. Covariate-dependent HMMs allow initial and transition probabilities to vary with declared numeric covariates. Latent states are statistical model states; labels should not be treated as emotion, cognition, diagnosis, or causal mechanisms.

Synthetic data

paths <- list(
  s1 = c("A", "A", "B", "B", "C"),
  s2 = c("A", "B", "B", "C", "C"),
  s3 = c("C", "C", "B", "B", "A"),
  s4 = c("C", "B", "B", "A", "A"),
  s5 = c("A", "A", "B", "C", "C"),
  s6 = c("C", "C", "B", "A", "A")
)
data <- do.call(rbind, lapply(seq_along(paths), function(i) {
  data.frame(
    sequence_id = names(paths)[i],
    sequence_order = seq_along(paths[[i]]),
    state = paths[[i]],
    context = c("x", "x", "y", "y", "z"),
    condition = as.integer(i > 3L),
    stringsAsFactors = FALSE
  )
}))

Multichannel model

multi <- fit_multichannel_sequence_hmm(
  data,
  n_states = 2L,
  channel_cols = c("state", "context"),
  max_iter = 15L,
  seed = 2L
)
summarise_multichannel_sequence_hmm(multi)$fit
head(decode_multichannel_sequence_states(multi))
plot_multichannel_sequence_hmm(multi, channel = "state")

Covariate-dependent model

covariate <- fit_covariate_sequence_hmm(
  data,
  n_states = 2L,
  initial_covariate_cols = "condition",
  transition_covariate_cols = "condition",
  max_iter = 10L,
  inner_maxit = 30L,
  seed = 3L
)
summarise_covariate_sequence_hmm(covariate)$fit
predict_covariate_transition_probabilities(
  covariate,
  data.frame(condition = c(0, 1))
)
head(decode_covariate_sequence_states(covariate))

Reporting

Report channel coding, state count, starting seed, convergence status, log-likelihood history, AIC/BIC as descriptive criteria, covariate scaling, and any sensitivity analyses. Multiple starts and simulation recovery should be used before substantive interpretation.



Try the gp3sequences package in your browser

Any scripts or data that you put into this service are public.

gp3sequences documentation built on Aug. 23, 2026, 5:10 p.m.