msmbayes: Semi-Markov Multi-State Tool
- msmbayes is an R package for semi-Markov multi-state modelling of intermittently observed panel data using phase-type approximations to model sojourn times.
- It reformulates semi-Markov models as hidden Markov models, allowing efficient likelihood evaluation via matrix exponentials and forward recursion.
- The package supports Bayesian and maximum likelihood inference with covariates, moment matching, and fast Laplace approximations for practical analysis.
msmbayes most directly denotes the R package introduced for stable and practical semi-Markov modelling of intermittently observed multi-state data (Jackson, 28 Aug 2025). In that sense, it provides Bayesian or maximum likelihood estimation for multi-state models with general state structures and covariates by combining structured phase-type approximations with a hidden Markov model representation. The supplied arXiv sources also show that searches for the string msmbayes can return unrelated Bayesian methods in econometrics, classification, tensor regression, multiple-systems estimation, and Markov-switching time series (Walker, 2024, Kim et al., 2022, Marsh et al., 9 Jan 2026, Zhang et al., 2012, Gankhuu, 2024). The dominant technical meaning, however, is the semi-Markov multi-state package and its associated methodology.
1. Name, scope, and disambiguation
In the semi-Markov literature, msmbayes is an R package that makes general semi-Markov multi-state modelling practical for intermittently observed (panel) data, with arbitrary state-transition structures, semi-Markov sojourn times via phase-type approximations to Gamma or Weibull families, and covariates affecting both sojourn times and next-state probabilities (Jackson, 28 Aug 2025). Its central methodological move is to express a semi-Markov model as a hidden Markov model, so that likelihood evaluation becomes tractable through matrix exponentials and a forward recursion.
The same search term is not unique across Bayesian methodology. The supplied sources associate it with several technically distinct objects. That ambiguity is substantive rather than lexical: the underlying statistical problems differ in state spaces, likelihoods, priors, and inferential targets.
| Usage in supplied sources | Object | Domain |
|---|---|---|
| msmbayes | R package | semi-Markov multi-state modelling |
| “A Bayesian Perspective on the Maximum Score Problem” | Bayesian inference framework | binary choice under median independence |
| BayesMSMW | R code/software | multi-source multi-way prediction |
| Neural MSE methods linked in search contexts | amortized SBI framework | hidden-population estimation |
A common source of confusion is therefore to treat msmbayes as a single cross-domain acronym. The supplied sources suggest instead that it should be read contextually: in multi-state modelling it refers to a specific package, whereas in nearby search results it can denote unrelated Bayesian frameworks.
2. Semi-Markov model and hidden Markov embedding
The package’s primary modelling target is an intermittently observed semi-Markov process on observable states (Jackson, 28 Aug 2025). If denotes time since entry into the current state , the transition hazard to state is , with total hazard
The Markov special case is recovered when is constant in ; the semi-Markov case allows explicit time-since-entry dependence.
The package represents semi-Markov sojourns through phase-type distributions. For state , one chooses a transient subgenerator , an initial probability vector 0, and exit vector 1. The survival, density, moments, and hazard are
2
3
4
5
This construction embeds each observable state 6 into latent phases 7 of a continuous-time Markov chain on an expanded latent state space with generator 8.
For an observation interval 9, the latent transition matrix is
0
Observed states are handled through deterministic emissions: the observed state 1 determines which latent phases are admissible via projection matrices 2. With observations 3 at times 4, the likelihood is evaluated by a forward recursion on the latent state space. Writing 5 and 6 for forward probabilities just before 7,
8
with normalization
9
and log-likelihood
0
This formulation is what makes arbitrary state-transition graphs, including cycles and competing risks, computationally manageable for panel data.
3. Structured phase-type approximation and moment matching
A central technical issue in semi-Markov modelling is identifiability. Unconstrained phase-type distributions introduce many latent parameters, which is problematic under intermittent observation. The package addresses this by restricting the phase-type family to a minimal acyclic structure, described as Coxian/Erlang–Exp, and by moment-matching that structure to simpler target families such as Gamma or Weibull (Jackson, 28 Aug 2025).
The restricted family is a mixture of two components: Exponential1 with probability 2, and Erlang3 + Exponential4 with probability 5. It exactly reproduces a Gamma with integer shape 6 when 7 and 8. The target family is specified through its first three moments. For Gamma9, the mean and variance are 0 and 1, with normalized moments
2
For Weibull with shape 3 and scale 4,
5
6
with normalized moments
7
The package implements a closed-form solution for 8 derived from moment matching.
The feasibility region depends on the number of phases. With 9 phases, Gamma shapes 0 must satisfy 1; for Weibull, the supported 2 increases with 3, with the paper reporting that for 4 phases, 5 is supported up to about 6, and for 7, up to about 8 (Jackson, 28 Aug 2025). The practical implication stated in the paper is that inference becomes far more stable when the model is parameterized by shape and scale per semi-Markov state, plus next-state probabilities, rather than by unconstrained latent phase transition rates.
4. Inference, covariates, and software structure
The package supports maximum likelihood, Laplace approximation, and full Bayesian inference (Jackson, 28 Aug 2025). Maximum likelihood is obtained by evaluating the latent-state log-likelihood through forward recursion and matrix exponentials and optimizing with Stan’s L-BFGS; the posterior mode under improper uniform priors equals the MLE. A Laplace approximation around the mode uses the Hessian-derived covariance to provide a multivariate normal approximation. Bayesian inference is implemented through Stan’s NUTS, with normal priors for log-intensities and covariate effects and truncated normal priors for shape parameters constrained by the moment bounds implied by the chosen number of phases.
Covariate effects enter two distinct components. First, sojourn times are modelled through an accelerated failure time scaling on the latent within-state transition rates:
9
0
Second, next-state probabilities are modelled through a multinomial logistic parameterization. Relative to a baseline destination 1,
2
These combine to give destination-specific latent exit intensities
3
4
The interpretation is explicit in the paper: 5 scales the speed of leaving state 6, whereas 7 tilts the exit toward particular destinations.
The modelling workflow is correspondingly structured. Data are supplied in panel form with columns such as id, time, state, and covariates, under the assumption that covariates are piecewise-constant between observation times. The analyst specifies the transition graph, selects which observable states are semi-Markov, chooses Weibull or Gamma approximations and the number of phases, and defines covariate formulas for Markov intensities, semi-Markov sojourn scale, and next-state logits. Fitting is then performed with method = "mcmc", "laplace", or "mle". Posterior summaries are produced through the posterior and tidybayes packages, while prediction functions evaluate 8 over user-defined horizons. The package also exposes utilities for moment matching and feasibility checking, including shapescale_to_rates, gamma_shape_in_bounds, weibull_shape_in_bounds, weibull_shape_ubound, mean_nphase, var_nphase, skewness_nphase, qnphase, and n3_moment_bounds.
5. Validation, empirical behaviour, and limitations
The paper validates the software with simulation-based calibration and an application to cognitive function decline (Jackson, 28 Aug 2025). The SBC exercises cover three model classes: a Markov model with age–sex covariates on infection and recovery rates; a semi-Markov model using a 5-phase phase-type approximation to a Weibull sojourn; and a competing-risks model including absorbing death. The reported result is that HMC posteriors passed SBC, with rank histograms approximately uniform across parameters, whereas the Laplace approximation, although fast, tended to bias shape parameters upward and underestimate uncertainty.
Runtime and convergence comparisons are similarly explicit. The Laplace approximation ran at about 9 of HMC runtime and was useful as a fast approximation, but HMC delivered the calibrated posterior benchmark. Frequentist MLE failed to converge in most simulated datasets: the paper reports a 0 failure rate for a Markov model and a 1 failure rate for a two-phase direct-rate semi-Markov model fitted in msm. The stated interpretation is that Bayesian inference and the moment-matched shape–scale phase-type parameterization offer a stability advantage under the intermittent-observation setting.
The ELSA application involves 2 living cognitive states plus death, with transitions between adjacent living states and to death, and covariates age, sex, and education. Semi-Markov models with 5-phase Weibull or Gamma approximations were used in each living state, and Laplace approximation was adopted because the model expanded to 3 latent states. The reported posterior modes were 4 for the Markov model, 5 for the Gamma semi-Markov model, and 6 for the Weibull semi-Markov model. Shape parameters below 7 in several living states indicated decreasing hazard with time since entry, which the paper interprets as evidence for semi-Markov behaviour. Covariate effects were directionally structured: age increased death relative to progression or recovery and increased progression relative to recovery; education lowered progression relative to recovery; women had lower death risk.
The principal limitations are also stated directly. Matrix exponentials scale with the size of the latent state space, so the computational burden rises sharply with the number of semi-Markov states and phases. Intermittent observation limits information about exact sojourn distributions, which is why the paper recommends avoiding unconstrained phase-type families and instead preferring 8–9 phases with moment matching. For Weibull models with decreasing hazard, 0 phases capture the behaviour reasonably well, but tails at 1 are hard to match exactly. Phase-count selection is therefore practical rather than purely formal: the paper recommends starting with 2 or 3 and increasing only if fit or posterior predictive checks indicate a need.
6. Other meanings in the Bayesian literature
The supplied arXiv sources indicate that msmbayes is also entangled with several unrelated Bayesian research programs. One such program is a Bayesian treatment of the maximum score problem, in which a median-independent threshold-crossing binary choice model is shown to be observationally equivalent to a heteroskedastic probit model, with a Gaussian process prior on 4 and Gibbs sampling based on Albert–Chib latent-variable augmentation and a 10-component Gaussian mixture approximation to 5 errors (Walker, 2024). Another is BayesMSMW, a Bayesian predictive model for multi-source multi-way data that uses a low-rank tensor coefficient structure, source-specific inverse-gamma variance components, and Gibbs sampling for continuous or probit outcomes (Kim et al., 2022).
Search results may also surface neural methods for Multiple Systems Estimation, where a Poisson log-linear model for hidden-population size is combined with amortized simulation-based inference through Neural Bayes Estimators and Neural Posterior Estimators, including explicit handling of censoring by masking during training (Marsh et al., 9 Jan 2026). Additional nearby collisions include Bayesian Markov-switching VAR methodology with conjugate matrix-normal/inverse-Wishart priors and “duplication removal” in regime vectors (Gankhuu, 2024), and fully Bayesian multicategory support vector machines that reinterpret the Lee–Lin–Wahba MSVM as MAP estimation under a hinge-like pseudo-likelihood with matrix-normal priors and latent-margin augmentation (Zhang et al., 2012).
This suggests a practical rule for interpretation. In multi-state survival and event-history analysis, msmbayes refers to the semi-Markov R package and its phase-type/HMM construction. Outside that domain, the same string functions mainly as a search collision rather than a stable method name. For researchers encountering the term without context, the decisive discriminant is therefore not the word itself but the surrounding object: intermittently observed multi-state panel data imply the package of (Jackson, 28 Aug 2025), whereas binary choice, tensor prediction, hidden-population estimation, regime-switching VARs, and multicategory large-margin classification imply distinct Bayesian frameworks.