Red Door Analytics

RDA morgana

Bayesian flexible survival models built on the merlin engine. Version 1 is installable for Stata today; the next Stata release and the multilevel mixed-effects R implementation are both in development alongside merlin v2.

Stata package · version 1 availableStata v2 · in developmentR package · in development

In build

The next release

Due November–December 2026

Available now Stata v1 from GitHub development release

One email, when it lands. Nothing else, and you can unsubscribe from it.

Bayesian survival · R + Stata

What morgana does

morgana brings full Bayesian inference to the merlin survival engine — every flexible parametric survival model merlin fits, with posterior uncertainty instead of a multivariate-normal approximation, built for HTA extrapolation under explicit priors. It comes in two implementations: a Stata package available today, and a full multilevel mixed-effects R package in active development.

In Stata, morgana is a prefix command. Placed in front of stmerlin, it estimates the model with Stata's bayesmh — turning any flexible parametric survival model stmerlin can fit (Royston-Parmar and other spline-based models, the standard parametric distributions, the Cox model, with time-dependent effects via restricted cubic splines) into its Bayesian counterpart, and passing bayesmh options such as priors straight through. Because stmerlin is itself a convenience wrapper around the merlin engine, you get accessible Bayesian flexible parametric survival in familiar Stata syntax with minimal extra code.

In R, morgana is a deeper Bayesian frontend to the engine. It hands merlin's differentiable joint log-density — built via TMB — straight to the No-U-Turn Sampler through tmbstan, so every family, multilevel structure, time-dependent effect, cure-model variant, and excess-hazard specification merlin fits in the frequentist paradigm is available with full Bayesian uncertainty, under one API. Because a morgana fit is merlin-parameterised, the two stay in lockstep — the same prediction kernel, estimand roster, and standardisation layer — with draws stored as posterior::draws_array for the Stan / bayesplot / tidybayes ecosystem. This implementation is in active development.

Capabilities

Bayesian inference across the whole merlin model class

These capabilities span both implementations. The Stata package delivers Bayesian estimation of any stmerlin model today, through bayesmh; the in-development R package fits each model on the merlin engine directly via tmbstan and the No-U-Turn Sampler, extending the same idea to the full multilevel mixed-effects model class.

FAMILIES

Every merlin family

Royston-Parmar and log-hazard splines, M-splines, the standard parametric families, mixture and non-mixture cure models, and excess-hazard (relative survival).

MULTILEVEL

Nested random effects

Up to two nested levels of Gaussian random effects, integrated under the fitted prior — marginal, population-averaged predictions by default.

SAMPLER

NUTS, no approximation

Hamiltonian Monte Carlo via tmbstan over merlin's exact log-density — not a multivariate-normal approximation to a frequentist fit.

PRIORS

Prior-specification DSL

Weakly-informative defaults, with informative priors designed for HTA extrapolation use cases.

STANDARDISATION

Bayesian g-formula

morgana_standardise() gives population-standardised survival, RMST, and marginal causal contrasts — the band is the posterior over the estimand, no delta method or sandwich.

ECOSYSTEM

draws_array native

Posterior draws as posterior::draws_array, ready for bayesplot, tidybayes, and the merlin health-economics toolkits without an approximation step.

Installation

Get started

morgana comes in two implementations — the Stata package is available now; the R package is in active development.

* Stata · requires the merlin and stmerlin packages
net install morgana, from("https://raw.githubusercontent.com/RedDoorAnalytics/morgana/main/")

R — in active development (v0.0.0.9001). A public release is planned; get in touch if you'd like early access.

Examples

A first model

The Stata prefix is released and runs today. The R interface is still being designed, so the block beside it shows where it is heading.

Planned syntax. The blocks marked planned show the interface being built, not a command you can run today. They may change before release.

Rplanned
library(morgana)
library(survival)

# the same flexible parametric model, sampled with NUTS through tmbstan
fit <- morgana(
  Surv(stime, died) ~ trt,
  distribution = "rp", df = 3,
  data = pbc.merlin,
  chains = 4, iter = 2000
)

summary(fit)        # draws stored as a posterior::draws_array
Stata
* a Bayesian flexible parametric (Royston-Parmar) survival model
* the morgana prefix estimates the stmerlin model with bayesmh
morgana : stmerlin hormon, dist(rp) df(3)

* pass an informative prior straight through to bayesmh
morgana, prior({hormon}, normal(0.3, 0.03)) : stmerlin hormon, dist(rp) df(3)
The merlin family

The Bayesian engine of the family

morgana is the Bayesian engine in the merlin family. merlin is the frequentist engine; pendragon builds multi-state and competing-risks models on top of either engine. The Stata morgana package is available now; the R implementation is in active development.

Worked examples and tutorials for the family are in our Resources.

Cite

Citing morgana

morgana does not have a methods paper yet — cite the software itself. The engine underneath it is merlin, whose framework paper is on the publications page.

@misc{morgana2026,
  author = {Crowther, Michael J.},
  title  = {{morgana: Bayesian flexible parametric survival models on the merlin engine}},
  year   = {2026},
  url    = {https://github.com/RedDoorAnalytics/morgana},
  note   = {Red Door Analytics}
}

Considering Bayesian survival extrapolation for an HTA submission?

morgana is built for exactly this — full posterior uncertainty under HTA-ready priors. Talk to us about using it on your dossier.

Get in touch Start a project