Skip to contents

Markov Ordinal State Transition models.

Compute and plot state occupancy probabilities (SOPs) and contrasts from first- and second-order Markov models of ordinal health-state trajectories.

Installation

Install the development version from GitHub with pak:

install.packages("pak")
pak::pak("scjohannes/mostr")

SOP Workflow

This example simulates ordinal outcomes from a viral respiratory disease trials, fits a proportional-odds Markov transition model with orm_markov(), estimates marginal treatment-arm SOPs, adds uncertainty, and plots the result.

library(mostr)
library(rms)
library(ggplot2)

set.seed(20260526)

trial <- sim_markov(
  "actt2",
  n_patients = 300,
  follow_up_time = 28,
  treatment_prob = 0.5,
  treatment_effect = log(0.8),
  seed = 20260526
)

markov_data <- prepare_markov_data(trial, absorbing_state = 8)

dd <- datadist(markov_data)
options(datadist = "dd")

fit <- orm_markov(
  y ~ rms::rcs(time, 4) + tx + yprev,
  data = markov_data,
  id_var = "id",
  opt_method = "LM",
  scale = TRUE
)

sop <- avg_sops(
  fit,
  variables = list(tx = c(0, 1)),
  times = 1:28,
  y_levels = fit$yunique,
  absorb = "8"
) |> inferences(
  method = "delta"
)

plot_sops(sop, facet_var = NULL, linetype_var = "tx") +
  labs(
    x = "Day",
    y = "State occupancy probability"
  )

Use orm_markov(), vglm_markov(), or blrm_markov() for package model-based SOP and diagnostic workflows. Raw rms, VGAM, or rmsb fits do not carry the wrapper provenance and stored-data contracts those workflows require.

Learn More

Read the package website for tutorials and the function reference.

After installation, see:

vignette("full-po-sops", package = "mostr")
vignette("analytical-confidence-intervals", package = "mostr")
vignette("partial-po-vglm-sops", package = "mostr")
vignette("second-order-orm-sops", package = "mostr")
vignette("many-levels-previous-state-spline", package = "mostr")
vignette("factor-time-orm-sops", package = "mostr")
vignette("bayesian-rmsb-sops", package = "mostr")
vignette("mvn-vs-bootstrap-orm-sops", package = "mostr")

Methodological Foundations

The statistical methods behind mostr were developed by Frank Harrell and colleagues. mostr wraps these methods in a workflow for fitting models, computing estimates, adding uncertainty, and plotting. If you use mostr, please consider citing the foundational paper:

Rohde MD, French B, Stewart TG, Harrell FE Jr (2024). “Bayesian Transition Models for Ordinal Longitudinal Outcomes.” Statistics in Medicine, 43(18), 3539–3561. doi:10.1002/sim.10133

For a detailed introduction with worked case studies, see the chapter Semiparametric Ordinal Longitudinal Models in Frank Harrell’s Regression Modeling Strategies.

Inspiration

The design of mostr is heavily inspired by the philosophy and workflow of the marginaleffects package: fit a model first, then compute the quantities you care about from it. Functions such as avg_sops(), avg_time(), and avg_comparisons() average predictions over patients, inferences() adds uncertainty in a separate step, and results are plain data frames with estimate, std.error, conf.low, and conf.high columns. If you use mostr, please also consider citing marginaleffects:

Arel-Bundock V, Greifer N, Heiss A (2024). “How to Interpret Statistical Models Using marginaleffects for R and Python.” Journal of Statistical Software, 111(9), 1–32. doi:10.18637/jss.v111.i09

Data Provenance

The included violet_baseline dataset and the model in sim_markov("violet") come from simlongord, a simulated trial that Frank Harrell based on the VIOLET trial (Harrell, 2022).

Funding

This project has received funding from the European Union’s Horizon Europe research and innovation program under grant agreement No 101156304.