RDA pendragon
Multi-state and competing-risks survival models in R and Stata, built on the merlin engine and its Bayesian sibling morgana — transition probabilities, length of stay, and the health-economic outputs, with frequentist or Bayesian uncertainty.
Coming
October 2026
Not yet released pendragon is in build for R and Stata.
Registered
We will email you once, when pendragon is released.
One email, when it lands. Nothing else, and you can unsubscribe from it.
A confirmation is on its way to your inbox.
What pendragon does
pendragon assembles transition-specific survival fits into multi-state and competing-risks models, then computes transition probabilities, length of stay, restricted mean time in state, and value-weighted occupancy — by exact Aalen-Johansen product integration or by simulation, with confidence or credible bands.
It comes in two implementations that share one design. The Stata package is a complete rewrite, with a new syntax, of Michael Crowther's multistate package (no longer developed), built on the current merlin engine for grid-invariant, machine-exact results and a large speed-up. The R package, pendragon-r, is the parallel implementation the Stata one is built towards, feature for feature.
Like merlin, pendragon keeps the multi-state machinery out of the engine: merlin (or morgana) fits each transition; pendragon stitches the transitions into a state space. merlin builds each road; pendragon stitches the roads into a realm. A fitted transition is reduced to two operations — draw parameters, evaluate the hazard — so frequentist (merlin) confidence bands and Bayesian (morgana) credible bands flow through identical code, and engines can even be mixed within one transition matrix.
From transition fits to a state space — and a cost-effectiveness model
Transition matrices
mstate-style transition matrices assembled from one merlin or morgana fit per transition, with clock-forward (Markov) and clock-reset (semi-Markov) semantics.
Exact Aalen-Johansen
Transition probabilities via an exact matrix-exponential product integral — grid-invariant and machine-exact — or by microsimulation, alongside length of stay and restricted mean time in state.
Frequentist or Bayesian bands
Delta-method or draw-based (PSA) intervals, built once against a held merlin object and injected many times — merlin confidence bands or morgana credible bands through identical code, engines may even be mixed within one model.
Background-mortality anchoring
Additive or constrained relative-survival anchoring of the death transitions, with a life-table helper; delayed entry and left truncation via Chapman-Kolmogorov.
Health-economic layer
Discounted QALYs, life-years, and costs; ICERs, CEACs, and expected value of perfect information; partitioned-survival models; g-formula standardisation and covariate-pattern contrasts of any statistic.
Against ground truth
Validated to machine / Monte-Carlo precision against analytic results; in Stata, a full certification suite passes against the current merlin engine.
Get started
pendragon is in active development in both R and Stata, and is not yet on SSC or CRAN. A public release is planned — get in touch if you'd like early access.
R — pendragon-r, the parallel R implementation, is in active development. Get in touch for early access to either implementation.
A first model
pendragon is in build. Both blocks were run on its development code, and neither is installable from this site yet. The Stata block also needs merlin 3.0, not yet released, and Stata 19.5 or later.
Development version. The blocks marked development version were run on the package’s development code. It is not yet installable from this site, and its interface may change before release.
library(pendragon)
library(merlin)
library(survival)
# simulated illness-death cohort: healthy ("start") -> ill -> dead ("dth")
set.seed(1)
n <- 1000
trt <- rbinom(n, 1, 0.5)
t12 <- rexp(n, 0.20 * exp(-0.4 * trt)) # healthy -> ill (treatment slows it)
t13 <- rexp(n, 0.05) # healthy -> dead
t23 <- rexp(n, 0.30) # ill -> dead
ill <- as.integer(t12 < pmin(t13, 10))
t_ill <- pmin(t12, t13, 10)
t_dth <- ifelse(ill == 1, pmin(t12 + t23, 10), t_ill)
d <- data.frame(id = 1:n, trt, ill, t_ill, dth = as.integer(t_dth < 10), t_dth)
# transition-long data, one Weibull model per transition, the multi-state model
ms <- pendragon_set(d, id = "id", status = c("ill", "dth"),
time = c("t_ill", "t_dth"))
fits <- lapply(1:3, function(k) merlin(Surv(start, stop, status) ~ trt,
data = ms[ms$trans == k, ],
family = "weibull"))
msm <- pendragon_msm(attr(ms, "tmat"), transitions = fits)
# P(in each state at 1, 5, 10 years | healthy at 0) if treated, 95% bands
tp <- transition_probs(msm, newdata = data.frame(trt = 1), times = c(1, 5, 10),
from = 1, uncertainty = "auto", B = 500, seed = 1)
cbind(time = tp$times, round(tp$point, 3))
cbind(time = tp$times, round(tp$band_lo, 3))
cbind(time = tp$times, round(tp$band_hi, 3))* simulated illness-death cohort: 1 = well, 2 = ill, 3 = dead;
* treatment slows death after illness (hazard ratio 0.6)
clear
set obs 1000
set seed 2026
generate pid = _n
generate trt = runiform() < 0.5
generate t12 = rexponential(5) // well -> ill
generate t13 = rexponential(20) // well -> dead
generate rf = min(t12, t13, 10)
generate rfi = t12 < min(t13, 10)
generate os = cond(rfi, min(rf + rexponential(1 / (0.5 * 0.6^trt)), 10), rf)
generate osi = os < 10
* transition-long data and one Weibull model per transition
pendragon set, id(pid) states(rfi osi) times(rf os)
matrix tmat = r(transmatrix)
forvalues k = 1/3 {
merlin (_stop trt, family(weibull, failure(_status) ltruncated(_start)) ///
timevar(_stop)) if _trans`k' == 1
estimates store m`k'
}
* treated vs untreated over 10 years: state utilities and annual costs,
* discounted at 3.5% a year, with 1000 probabilistic sensitivity draws
range tt 0 10 101
pendragon_cea, transmatrix(tmat) models(m1 m2 m3) timevar(tt) ///
at1(trt 1) at2(trt 0) utility(1 0.6 0) cost(1000 8000 0) ///
wtp(0 10000 20000 30000 50000) seed(2026)
matrix list r(ceac)The multi-state layer of the family
Worked examples and tutorials for the family are in our Resources.
Try it in your browser: the multi-state & competing-risks explorer and the partitioned-survival explorer — interactive companions to pendragon's model class, with one-click export.
Citing pendragon
pendragon does not have a methods paper yet — cite the software itself. For the multi-state methodology, the paper below remains the reference.
@misc{pendragon2026,
author = {Crowther, Michael J.},
title = {{pendragon: multi-state and competing-risks models on the merlin engine}},
year = {2026},
url = {https://reddooranalytics.se/software/pendragon/},
note = {Red Door Analytics}
}
The methods lineage: this paper describes the approach pendragon builds on.
@article{crowther2017,
author = {Crowther, M. J. and Lambert, P. C.},
title = {{Parametric multistate survival models: flexible modelling allowing transition-specific distributions with application to estimating clinically useful measures of effect differences}},
journal = {Statistics in Medicine},
year = {2017},
volume = {36},
number = {29},
pages = {4719--4742},
doi = {10.1002/sim.7448}
}
RIS and the full library are on the publications page.