Code for implementing a Joint Model of recurrent and terminal events with Discretely-distributed non-parametric Frailty.
Masci C, Spreafico M & Ieva F. Joint modelling of recurrent and terminal events with discretely-distributed non-parametric frailty: application on re-hospitalizations and death in heart failure patients. arXiv:2311.04103
This repository also contains the code for conducting a simulation study that is not included in the arXiv preprint.
We cannot provide the original administrative data analysed in Section 4 due to confidentiality restrictions. We therefore provide a pseudo-data dataset that allows researchers to reproduce the analyses illustrated in Section 4, understand how the code should be run, and inspect how the results are generated, displayed, and interpreted.
These analyses use the pseudo-data example (./data/fake_dataRD.Rdata) and are intended to illustrate the JMDF methodology, rather than to reproduce the Section 4 application dataset.
-
Files:
- 01_jmdf_selection.R reproduces the model-selection results reported in Figure 2.
- 02_main_JMDF.R reproduces the pseudo-data analyses underlying Figures 3 and 4 and the corresponding Table 7, and saves the fitted objects.
- 03_main_JMparametric.R fits the Rondeau et al. (2007) and Ng et al. (2023) models on the pseudo-data example and saves the fitted objects, Table 1, and Figure 6.
- 04_fixed_effect_comparison.R reproduces the hazard-ratio comparison reported in Figure 5.
-
Sub-folder ./data/ contains the pseudo-data dataset and its variable legend:
- data_legend.txt: Variables legend of dataset 'fake_dataRD.Rdata'.
- fake_dataRD.Rdata: Datasets related to 300 fake patients for recurrent (dataR) and terminal (dataD) events (see Appendix A of the arXiv reference for further details).
-
Sub-folder ./functions/ contains auxiliary functions used by the main scripts:
- JMdiscfrail.R: Function implementing a joint model of recurrent and terminal events with discretely-distributed non-parametric frailty. This file also contains functions for computing (classification) log-likelihood.
- JointFrailtyNg.R: Function that implements the joint frailty model with bivariate Gaussian random effects by Ng et al. (2023). This function was taken from https://github.com/RichardTawiah/JointFrailty.
- data_format.R: Function for re-formatting dataset.
- jmdf_plots.R: Functions for creating manuscript figures.
- stratified_base_surv.R: Function that computes th stratified survival probability curves for recurrent and terminal processes from a joint model fitted using JMdiscfrail().
-
Sub-folder ./results/ contains the fitted model objects and the tables and figures generated by the application scripts:
- ./results/figures/ contains the figures saved as
.pdffiles, with filenames corresponding to the manuscript figures; - ./results/tables/ contains the tables saved as
.csvfiles, with filenames corresponding to the manuscript tables.
- ./results/figures/ contains the figures saved as
-
Sub-folder ./simstudy/ contains the files to reproduce the simulation study. See README_SIMSTUDY for further details.
- R software.
- Packages: data.table, dplyr, frailtyPenal, ggplot2, ggpubr, gt, MASS, mcprogress, mvtnorm, parallel, survival.
(Last update: August 28th, 2026)