Red Door Analytics
v2.0 development version
GPL-3 · open source
10 baseline families
under one formula syntax
2 nested random-effect levels
with intercepts and slopes
3 integration methods
Laplace · GHQ · AGHQ

merlin for R is the 2026 ground-up rewrite of the merlin framework. Its C++ kernels compute analytic gradients on almost every path and analytic Hessians on most; the Laplace integration path uses TMB's automatic differentiation.

The scope is survival regression and generalised linear regression: alongside the survival families, the engine fits Gaussian, Bernoulli, binomial, Poisson, gamma, negative binomial, beta and ordinal outcomes, with the same random-effects syntax. Several outcomes fit in one model with merlin(outcomes = list(...)): stacked, or linked through shared random effects with loadings, which covers joint models of a longitudinal marker and a survival time, and competing risks. For multi-state models today, see merlin for Stata; in R they are coming in pendragon, and Bayesian inference in morgana. Both are built on this engine and in active development.

v2.0 targets a CRAN release as merlin 2.0.0, under the CRAN name of the original merlin R package (archived November 2024).

Install and fit

Install and fit a first model

A short example fits a Royston-Parmar model to individual patient data from several trials, with centres nested within trials. The formula uses lme4-style (1 | a/b) nesting; AGHQ at seven nodes is the default integration method. v2.0 is a development version: built and tested, not yet released. Windows and Apple-silicon Macs with R 4.6 can install a ready-built copy; other set-ups compile it from source, so Windows needs Rtools and a Mac the Xcode command line tools.

R · merlin v2.0 (dev)
# merlin for R v2.0, development version
# (not yet on CRAN; it may change before 2.0.0)
install.packages("merlin",
  repos = c("https://reddooranalytics.se/install/r",
            "https://cloud.r-project.org"))

# Windows, R 4.6: a ready-built copy, no Rtools needed
install.packages(c("TMB", "Rcpp", "survival",
  "splines2", "checkmate", "cli", "rlang"),
  repos = "https://cloud.r-project.org")
install.packages(
  "https://reddooranalytics.se/install/r/src/contrib/merlin_2.0.0.9003.zip",
  repos = NULL, type = "win.binary")

# Mac with Apple silicon, macOS 14 or later,
# and R 4.6: a ready-built copy, no compiler needed
install.packages(c("TMB", "Rcpp", "survival",
  "splines2", "checkmate", "cli", "rlang"),
  repos = "https://cloud.r-project.org")
install.packages(
  "https://reddooranalytics.se/install/r/src/contrib/merlin_2.0.0.9003.tgz",
  repos = NULL, type = "mac.binary")

library(merlin)
library(survival)

fit <- merlin(
  Surv(time, status) ~ trt + sex + age + (1 | trial/centre),
  data   = ipd,
  family = "rp",      # Royston-Parmar on log-cumulative-hazard
  # method = "laplace",  # AGHQ is the default; Laplace is often faster at two levels
  df     = 5          # 5 spline degrees of freedom
)

summary(fit)
ranef(fit)
predict(fit, newdata = nd, type = "surv", times = c(1, 5, 10))
Capabilities

What merlin for R does today

Ten baseline families, three integration methods, two nested random-effect levels, cure, relative-survival and time-dependent extensions, and several outcomes in one model.

01

Ten baseline families

Royston-Parmar splines on the log-cumulative-hazard scale, splines on the log-hazard scale, an M-spline hazard with closed-form cumulative hazard, a piecewise-exponential hazard, plus the standard parametric distributions (exp / Weibull / Gompertz / log-normal / log-logistic / ggamma).

02

Mixture and non-mixture cure

Both forms attach to any proportional-hazards family with covariate-dependent cure proportion. Combine with multilevel random effects for IPD meta-analytic extrapolation across trials.

03

Multilevel structure

Up to two nested levels of Gaussian random effects with intercepts and slopes under independent, diagonal, or unstructured within-level covariance.

04

Time-dependent effects

On the Royston-Parmar, log-hazard, exponential, Weibull and Gompertz families, via restricted cubic splines in log(t) or fractional polynomials in t. Composes with cure and relative survival.

05

Relative survival

Excess-hazard modelling via the bhazard argument, with a merlin_bhazard() helper that takes a life table in long format: age, sex, year and the population hazard.

06

Three integration methods

AGHQ (the default, with mean-variance node placement, or Liu-Pierce mode-curvature as an option), TMB Laplace, and non-adaptive GHQ as a check. Gradients are analytic on almost every path, in C++; the Laplace path uses TMB's automatic differentiation.

Performance

Timings

merlin's fits use analytic gradients on almost every path (TMB's automatic differentiation on the Laplace path) behind a single compiled engine, which makes it quick on the configurations it targets. We publish the measurements rather than a summary of them: wall-clock seconds beside the log-likelihood and coefficient each package returned on the same data, and the caveats that apply to timing anything on one machine.

Measured timings and comparisons →

For prognostic modelling

Prognostic models across sites and trials

Multilevel parametric survival regression with flexible baselines and a full set of predictions is well suited to prognostic-model work, including multi-site cohorts and IPD meta-analysis, where the model needs random effects for site or trial.

Validating those models — discrimination, calibration, Brier score and decision-curve net benefit, with bootstrap and cross-validation — is the job of gawain, our validation package for survival prediction models, in development for R and Stata.

If TRIPOD-aligned prognostic modelling is your use case

Get in touch — we're collecting requirements from teams using merlin for prognostic-model work.

For IPD meta-analysis

Trial-as-cluster, in a single fit

merlin's multilevel parametric survival models — trial-as-cluster Gaussian random effects with intercepts and slopes, under independent, diagonal, or unstructured covariance — fit a one-stage individual-patient-data (IPD) meta-analysis of survival directly. One model carries a shared baseline and trial-specific deviations on both the intercept and the treatment effect, so between-trial variation is estimated rather than pooled away, and every trial informs the extrapolation.

The methodological foundations are published: Crowther, Riley et al. (BMC Medical Research Methodology 2012) for Poisson IPD-MA; Crowther, Look & Riley (Statistics in Medicine 2014) for multilevel mixed-effects parametric survival applied to recurrent events and IPD meta-analysis; Hua, Burke, Crowther, Ensor, Tudur Smith & Riley (Statistics in Medicine 2017) on separating within-trial and across-trial information; Freeman, Sutton, Cooper, Gasparini, Crowther & Hawkins (Research Synthesis Methods 2024) for Bayesian pairwise meta-analysis with non-proportional hazards.

For evidence synthesis teams

Cochrane reviews, NICE evidence-synthesis dossiers and IPD meta-analyses with time-to-event outcomes are what merlin's multilevel models were built for. Get in touch — we're collecting case studies from real IPD meta-analyses.

Work with the team

The people who build merlin, on your project

When a multilevel survival model, an extrapolation for a submission, or a non-standard analysis has to be right, the team takes the work on directly — applied analysis, bespoke methods development, and model review. See how we work → or get in touch.

Methodology and citation

Published, cited, in active development

Framework paper
Crowther, MJ (2020)
merlin—A unified modeling framework for data analysis and methods development in Stata. Stata Journal 20(4):763–784.
R software paper
merlin: Flexible and Fast Survival Analysis in R
In preparation.
Source and documentation
GPL-3, with the repository opening at release
merlin for R is licensed GPL-3 and the repository becomes public at release. Reference documentation ships with the package: ?merlin in R.

Get started with merlin for R

A development version of v2.0 installs now, with the lines above. A CRAN release and releases for regulated use are in preparation. Get in touch for commercial support or bespoke methods development.

Get in touch → merlin Validated