---
pagetitle: Markov Ordinal
---
# Simulating Frequentist and Bayesian Operating Characteristics of Longitudinal Markov Ordinal Randomized Trials
The document linked below contains detailed descriptions and examples of simulating longitudinal ordinal outcomes for a two-treatment comparison. This is useful for simulating clinical trials such as COVID-19 therapeutic trials, and studying the Bayesian and frequentist operating characteristics of various tests applied to such data. Within-patient correlation is modeled by a first-order Markov process whereby the ordinal outcome in the previous time interval becomes a covariate for the current time interval. The proportional odds model is the basis for analysis, and this model is extended to account for non-proportional odds with respect to time, by use of the Peterson and Harrell (1990) partial proportional odds model.
Because Markov state transition models describe tendencies for being in the various levels of the ordinal outcome conditional on the previous state, the report pays much attention to the "unconditioning" or marginalization of the transition model to provide the more traditional state occupancy probabilities, to compute, e.g., the probability that a patient will be on a ventilator on day 10 as a function of treatment. When one of the outcome levels (events) is an absorbing state such as death, the occupancy probability for that state at time $t$ is the cumulative incidence of that event by time $t$.
The report covers
* how to specify a simulation model and simulate Bayesian and frequentist performance of methods
* how to derive a simulation model from the observed data from a completed study (here the VIOLET 2 study of Vitamin D in ICU patients)
* how to automatically compute the parameters of a simulation model to meet constraints such as the proportion of patients in all the outcome categories on given days of follow-up
* demonstrating that power of longitudinal analysis is significantly higher than from taking an ordinal outcome at a single day
* demonstrating that the longitudinal analysis has significantly higher power than a Cox model comparison of time to recovery, and knows how to handle death properly
* quantification of the power loss when the frequency of sampling within a patient is reduced after the patient reaches a certain state such as return to home
* showing how to use a single large study to estimate the relative efficiency of the treatment effect estimate as a function of the number of days of data collection
* showing how to quantify the boost in the effective number of patients by having multiple measurements per patient; for example 28 days of data per patient like those from VIOLET 2 effectively boosts the sample size by a factor of 5 compared to measuring an ordinal outcome at a single day
Power gains from using longitudinal data have major ramifications for sample size calculations and earlier decision making.
------
* **Report**: [html](sim.html) [pdf](sim.pdf)
* [Service functions](funs.r)
* [R Markdown script](sim.Rmd)
* [R Hmisc functions](https://github.com/harrelfe/Hmisc/blob/master/R/simMarkovOrd.r)
* [Another report](sim2.html) simulating frequentist power and Bayesian operating characteristics for a 3-level ordinal longitudinal outcome that also shows how to use published data to build a simulation model
* [Markov ordinal modeling examples on two simulated datasets](d2.html)
------
The document provides extensive examples and output for new R `Hmisc` package functions:
* `simMarkovOrd`: simulate ordinal longitudinal data under a first-order Markov process with a proportional odds model
* `soprobMarkovOrd`: compute state occupancy probabilities from the Markov model for transition probabilities
* `estSeqMarkovOrd`: run sequential Markov ordinal longitudinal clinical trial simulations
* `intMarkovOrd`: compute simulation parameters providing the best compromise on achieved state occupancy and/or transition probabilities against user-specified constraints
Until the new version of `Hmisc` is on CRAN, the latest `Hmisc` package source, as well as binary versions for Linux and Windows, may be found [here](https://hbiostat.org/R/Hmisc).
The report demonstrates many R programming techniques including
* parallel processing to speed up simulations
* using a hash to only run simulations when an input parameter or the source code changes
* using the `data.table` package for aggregating and reshaping data tables
* auto-sensing when html format is being produced
* automatically switching to interactive `plotly` graphics when creating the html version of the report
* dynamic creation of a sequence of R markdown `knitr` code chunks each with its own figure caption, using `Hmisc::markupSpecs$html$mdchunk`
* use of the beautiful [rmdreadthedown](https://github.com/juba/rmdformats) report template when producing html
* use of special LaTeX options when producing pdf