merlin for R
The ground-up R rewrite of the merlin engine — multilevel mixed-effects survival regression on an in-house C++ kernel layer with analytic gradients across every family, integration method, and random-effect configuration.
open source
under one formula syntax
in the last run with no skipped tests
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).
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.
# 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))
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.
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).
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.
Multilevel structure
Up to two nested levels of Gaussian random effects with intercepts and slopes under independent, diagonal, or unstructured within-level covariance.
Time-dependent effects
On any PH family via restricted cubic splines or fractional polynomials in log(t). Composes with cure and relative survival.
Relative survival
Excess-hazard modelling via the bhazard argument, with a merlin_bhazard() helper compatible with popEpi::popmort and relsurv::slopop.
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.
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.
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.
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.