Red Door Analytics
v0.1.1 pre-CRAN release · GPL-3
open source
10 baseline families
under one formula syntax
26,827 assertions passing
in the last run with no skipped tests
3 integration methods
Laplace · GHQ · AGHQ

merlin for R is the 2026 ground-up rewrite of the merlin framework's survival core. Built on an in-house C++ kernel layer with hand-derived analytic gradients across every family, integration method, and random-effect configuration — with TMB autodiff layered in for the Laplace integration path and OpenMP parallelism across clusters.

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 random effects shared across the linear predictor. Multi-state and competing risks live in pendragon; Bayesian inference in morgana — both built on this engine, and both in active development. Multi-outcome joint longitudinal–survival modelling returns to the R engine in v2.2+; for that today, see merlin for Stata.

v2.0 is pre-release and in active development. It targets a CRAN release as merlin 2.0.0, reclaiming the existing CRAN slot of the original merlin R package (archived November 2024).

Install and fit

From zero to a fitted model in three lines

A short example fits a Royston-Parmar model with patients nested within hospitals. The formula uses lme4-style (1 | a/b) nesting; AGHQ at seven nodes is the default integration method.

R · merlin v2 (in build)
# install.packages("pak")
pak::pak("RedDoorAnalytics/merlin-r")

library(merlin)
library(survival)

fit <- merlin(
  Surv(time, status) ~ trt + sex + age + (1 | hospital/patient),
  data   = my_data,
  family = "rp",      # Royston-Parmar on log-cumulative-hazard
  df     = 5           # 5 spline degrees of freedom
  # method = "aghq" is the default; "laplace" recommended for L=2 fits
)

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 first-class integration methods, two nested random-effect levels, and the cure / relative-survival / time-dependent extensions that the rest of the R survival ecosystem leaves underserved.

01

Ten baseline families

Royston-Parmar splines on the log-cumulative-hazard or log-hazard scale, a monotone 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 any PH family via restricted cubic splines or fractional polynomials in log(t). Composes with cure and relative survival.

05

Relative survival

Excess-hazard modelling via the bhazard argument, with a merlin_bhazard() helper compatible with popEpi::popmort and relsurv::slopop.

06

Three integration methods

AGHQ (default, Liu-Pierce mode-Hessian), TMB Laplace, and non-adaptive GHQ. Every fit path uses analytic gradients implemented in C++.

Performance

Timings

merlin's fit paths use analytic first and second derivatives 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

A second sub-specialty taking shape

merlin's substrate — multilevel parametric survival regression with flexible baselines and a full prediction surface — is well-suited to prognostic-model work, including the multi-site cohort and IPD-meta-analytic settings that current R prediction-modelling tools (rms, riskRegression, pec, survAUC) leave underserved.

A prediction-performance toolkit — discrimination (time-dependent C-statistic, AUC at a horizon), calibration (calibration-in-the-large, calibration slope, calibration plots), Brier score and Index of Prediction Accuracy, decision-curve analysis, and cluster-aware bootstrap / cross-validation for internal validation — is in development. Dynamic prediction and landmark analysis are part of the same work.

If TRIPOD-aligned prognostic modelling is your use case

The performance-evaluation toolkit is being prioritised in response to user demand. 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 capability — trial-as-cluster Gaussian random effects with intercepts and slopes, under independent, diagonal, or unstructured covariance — is the substrate that individual-patient-data (IPD) meta-analytic survival extrapolation has lacked in R. Existing tools force a choice between fixed-effects pooling (which discards between-trial variation), separate per-trial fits (which loses pooling efficiency), or non-survival adaptations of lme4 / nlme. merlin lets you specify the natural IPD-MA model as a single fit with shared baseline and trial-specific deviations on both the intercept and the treatment effect.

The methodological foundations are published: Crowther & Riley (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, 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, IPD meta-analyses, or NMA work with time-to-event outcomes — merlin's multilevel substrate is a direct fit. Get in touch — we're collecting case studies that push the multilevel implementation under realistic IPD-MA conditions.

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 modelling 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 for the Journal of Statistical Software. arXiv preprint going up before launch.
Source and documentation
GPL-3, with the repository opening at release
merlin for R is licensed GPL-3 and the repository becomes public with the v0.1.1 release. Reference documentation ships with the package: ?merlin in R.

Get started with merlin for R

The repository is not yet public. It opens with the v0.1.1 release, and a CRAN release is in preparation. Get in touch for early access — or for commercial support, validated releases for regulated use, or bespoke methods development, see merlin Validated.

Ask for early access → merlin Validated