| Title: | Bayesian Dynamic Borrowing with Flexible Baseline Hazard Function |
|---|---|
| Description: | Allows Bayesian borrowing from a historical dataset for time-to- event data. A flexible baseline hazard function is achieved via a piecewise exponential likelihood with time varying split points and smoothing prior on the historic baseline hazards. The method is described in Scott and Lewin (2026) <doi:10.1093/biostatistics/kxag006>, and a paper focused on the software is in Scott, Axillus, Lewin and Izmirlian (2026) <doi:10.48550/arXiv.2408.04327>. |
| Authors: | Darren Scott [aut], Sophia Axillus [aut], Grant Izmirlian [aut, cre] |
| Maintainer: | Grant Izmirlian <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 2.0.20 |
| Built: | 2026-10-20 00:04:40 UTC |
| Source: | https://github.com/cran/BayesFBHborrow |
Fits the Bayesian Flexible Baseline Hazard Model with Borrowing via MCMC/MH. Each sample in the Gibbs sampler is a piecewise exponential model, with prior over number and location of split points. Accommodates borrowing over a historical control arm as well as G-computation.
BayesFBHborrow(formula = NULL, data, data_hist = NULL, subset, na.action, CntlOnly = FALSE, model_choice = "mix", tuning_parameters = NULL, hyperparameters = NULL, iter = 1000, warmup_iter = 100, refresh = 0, verbose = FALSE, max_grid = 2000, standardise = TRUE, G_compute = FALSE, preprocess = TRUE, fnm_cnd_haz_0 = "cnd_haz_0", fnm_cnd_cumHz_0 = "cnd_cumHz_0", fnm_lml_mgnl_surv_0 = "lml_mgnl_surv_0", fnm_lml_mgnl_surv_1 = "lml_mgnl_surv_1", fnm_mgnl_haz_0 = "mgnl_haz_0", fnm_mgnl_haz_1 = "mgnl_haz_1", sfx = NULL, keep_bin_files = FALSE, n_chains = 1L, hpc_max_cores = 16, dbg = FALSE, ...)BayesFBHborrow(formula = NULL, data, data_hist = NULL, subset, na.action, CntlOnly = FALSE, model_choice = "mix", tuning_parameters = NULL, hyperparameters = NULL, iter = 1000, warmup_iter = 100, refresh = 0, verbose = FALSE, max_grid = 2000, standardise = TRUE, G_compute = FALSE, preprocess = TRUE, fnm_cnd_haz_0 = "cnd_haz_0", fnm_cnd_cumHz_0 = "cnd_cumHz_0", fnm_lml_mgnl_surv_0 = "lml_mgnl_surv_0", fnm_lml_mgnl_surv_1 = "lml_mgnl_surv_1", fnm_mgnl_haz_0 = "mgnl_haz_0", fnm_mgnl_haz_1 = "mgnl_haz_1", sfx = NULL, keep_bin_files = FALSE, n_chains = 1L, hpc_max_cores = 16, dbg = FALSE, ...)
formula |
Optional but most likely preferred. When using the formula/data interface, specify the formula in the form typically used in other survival models e.g. Surv(TOS, Event) ~ Trt + Oth + Covs + etc The first listed covariate must be the treatment variable. The rest can be continuous or factor. |
data |
Required. The current trial/study data.frame with a treated and a control arm. For the formula/data interface, there is no naming convention for variables as the user specifies these with the formula. For the data only interface, you must name the time to event variable 'tte', and the event variable 'event'. All covariates including the treatment indicator must have the 'X_' prefix. |
data_hist |
When fitting the full model with borrowing, the historical controls data.frame with variables named to agree with the current trial data.frame specified in the 'data' argument. Comments above regarding the formula/data versus data only interface apply here as well. |
subset |
When using the formula/data interface, you may also use
|
na.action |
When using the formula/data interface, you may also use
|
CntlOnly |
Set to |
model_choice |
Borrowing method. Determine the borrowing per split point by specifying the option "mix" (default) for a mixture of inverse gamma densities or "uni" for a single inverse gamma density. Otherwise, determine the borrowing once for all split points by specifying the option "all". |
tuning_parameters |
list with components |
hyperparameters |
list with components |
iter |
Number of iterations for MCMC sampler. |
warmup_iter |
Number of warmup iterations (burn-in) for MCMC sampler. |
refresh |
Number of iterations between printed screen updates. |
verbose |
Whether or not to print the progress to the console
every |
max_grid |
Grid size for the smoothed baseline hazard. Default value is 2000. |
standardise |
Whether or not to normalize the current trial baseline hazard to
unity and apply the same normalization constant to the historical
data. Default is |
G_compute |
If set to |
preprocess |
Controls the interpretation of the 'baseline' hazard consequent to
recoding of the input dataset(s). When set to |
fnm_cnd_haz_0 |
name prefix with a random hex suffix. The collection of
"snapped to common grid" samples from the posterior distribution of
the baseline hazards is a matrix of dimension |
fnm_cnd_cumHz_0 |
(see above) This file contains samples of the conditional baseline cumulative hazard. |
fnm_lml_mgnl_surv_0 |
(see above) This file contains samples of the logged negative logged control arm marginal survival function. |
fnm_lml_mgnl_surv_1 |
(see above) This file contains samples of the logged negative logged treated arm marginal survival function. |
fnm_mgnl_haz_0 |
(see above) This file contains samples of the control arm marginal hazard which have been derived as the finite difference quotient of the exponentiated values in the lml_mgnl_surv_0 file. |
fnm_mgnl_haz_1 |
(see above) This file contains samples of the treated arm marginal hazard which have been derived as the finite difference quotient of the exponentiated values in the lml_mgnl_surv_0 file. |
sfx |
The name of the subdirectory created in the current working directory to contain these binary files. Also used in the suffix of the file names. The default behavior is to give this a random 6 digit hex string so there's no need to specify this argument either. |
keep_bin_files |
Defaults to |
n_chains |
Number of chains to sample in parallel post warmup. This is determined automatically by the function depending on the capabilities of your machine and the OS you are using (unix alike [mac/WSL], HPC cluster, or windows). No need to set this |
hpc_max_cores |
If you use the HPC cluster either in the workbench or setting up an interactive node at the command line, you should request 'Rstudio large' and then set the number of cores to anything up to 32. You should request 16GB of ram so you might have to play with setting until you're given permission to open the session. At AZ I've had success with 16GB and 16 cores. In any case, set this to the number of cores you're able to get. |
dbg |
When running in command line mode, set to |
... |
Other arguments as needed. |
BayesFBHborrow implements our semiparametric Bayesian borrowing model allowing inferences on a current trial with commensurate Bayesian borrowing from a set of historical controls. The model supports covariate adjusted borrowing, which can reduce prior-data conflict and improve power when differences in outcomes are attributable to changes in covariate distribution. As the treatment effect estimator is non-collapsible, the marginal hazard ratio can be estimated via Bayesian G-computation, while still permitting an adjusted analysis to account for control group drift. The package now fully implements parallel computation using parallelly, future and future.apply.
Y |
Times on study in the 'data' argument data.frame, scaled to unit event rate. |
I |
Event indicators in the 'data' argument data.frame |
X |
Treatment indicator and pretreatment covariates in the 'data' argument data.frame, recoded if 'prepocess' is TRUE. |
Y_0 |
Times on study in the 'data_hist' argument data.frame, scaled to unit event rate. |
I_0 |
Event indicators in the 'data_hist' argument data.frame |
X_0 |
Pretreatment covariates in the 'data_hist' argument data.frame, recoded if 'prepocess' is TRUE. |
samples |
An 'iter' by ncol(X) + 3*J + 4 matrix containing all post warmup samples from the MCMC sampler: the model coefficients, the number of split points, hyperparameters mu and sigma2, the locations of all split points and the values of the piecewise exponential hazards corresponding to the current trial and to the historical controls data distributions. |
surv_dat |
Median together with 95 percent credible interval of posterior samples of the per arm conditional hazards/survival functions, per arm marginal hazard/survival functions, and marginal treatment effect at each time point on the fine meshed grid of length 'max_grid'. |
MTE_dens_dfs |
kernel density estimates for samples of the posterior distribution of the marginal treatment effect at information fraction 25, 50, 75 and 100 percent. |
T.if |
Times on study at 25, 50, 75 and 100 percent information. |
fnms |
File names of binary files of snapped to fine meshed grid hazard function samples from the posterior. Provided for calculating custom functionals of the hazard function posterior distribution. |
beta_acc_ratio |
Metropolis-Hastings algorithm acceptance ratio for current data model coefficients. Find value of cprop_beta in tuning_parameters which results in this being between 0.30 and 0.40. |
beta_0_acc_ratio |
Metropolis-Hastings algorithm acceptance ratio for historical data model coefficients. Find value of cprop_beta in tuning_parameters which results in this being between 0.30 and 0.40. |
call |
The call which produced the object. |
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
plot, summary, update methods for class
"BayesFBHborrow" objects
n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) ## using default settings for hyperparameters and tuning parameters ## formula interface ## cntls only; no cov's test_f0 <- BayesFBHborrow(Surv(tte, event)~1, data = DAT_hst, CntlOnly=TRUE, iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## cntls only; with cov's test_f1 <- BayesFBHborrow(Surv(tte, event) ~ X_01 + X_02 + X_03, data = DAT_hst, CntlOnly=TRUE, iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w/o borrow; no cov's: test_f2 <- BayesFBHborrow(Surv(tte, event) ~ X_trt, data = DAT_cc, iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w borrow, no cov's: test_f3 <- BayesFBHborrow(Surv(tte, event) ~ X_trt, data = DAT_cc, data_hist = DAT_hst, model_choice = 'mix', iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w/o borrow; w cov's: test_f4 <- BayesFBHborrow(Surv(tte, event) ~ X_trt + X_01 + X_02 + X_03, data = DAT_cc, model_choice = 'mix', iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w borrow, w cov's: test_f5 <- BayesFBHborrow(Surv(tte, event) ~ X_trt + X_01 + X_02 + X_03, data = DAT_cc, data_hist = DAT_hst, model_choice = 'mix', iter = 10, warmup_iter = 5, refresh = 0, verbose = FALSE)n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) ## using default settings for hyperparameters and tuning parameters ## formula interface ## cntls only; no cov's test_f0 <- BayesFBHborrow(Surv(tte, event)~1, data = DAT_hst, CntlOnly=TRUE, iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## cntls only; with cov's test_f1 <- BayesFBHborrow(Surv(tte, event) ~ X_01 + X_02 + X_03, data = DAT_hst, CntlOnly=TRUE, iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w/o borrow; no cov's: test_f2 <- BayesFBHborrow(Surv(tte, event) ~ X_trt, data = DAT_cc, iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w borrow, no cov's: test_f3 <- BayesFBHborrow(Surv(tte, event) ~ X_trt, data = DAT_cc, data_hist = DAT_hst, model_choice = 'mix', iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w/o borrow; w cov's: test_f4 <- BayesFBHborrow(Surv(tte, event) ~ X_trt + X_01 + X_02 + X_03, data = DAT_cc, model_choice = 'mix', iter = 200, warmup_iter = 50, refresh = 0, verbose = FALSE) ## trtd+cntls; w borrow, w cov's: test_f5 <- BayesFBHborrow(Surv(tte, event) ~ X_trt + X_01 + X_02 + X_03, data = DAT_cc, data_hist = DAT_hst, model_choice = 'mix', iter = 10, warmup_iter = 5, refresh = 0, verbose = FALSE)
BayesFBHborrow class
The coefficients extractor method for the BayesFBHborrow class
with functionality dependent upon whether you select the conditional
estimand or marginal contrast.
## S3 method for class 'BayesFBHborrow' coef(object, ...)## S3 method for class 'BayesFBHborrow' coef(object, ...)
object |
An object of class |
... |
Not used |
Every call to the function runs the sampler and then produces the
conditional estimand and marginal contrast for the
treatment/pretreatment variable effects. The argument G_compute
in the BayesFBHborrow call tells the print, plot, summary and
coef methods which version the user wants displayed.
G_compute=FALSE, then coef() will extract the
conditional logged hazard ratio coefficients.
If G_compute=TRUE then a table of showing the marginal
treatment contrast e.g. the difference between the log-logged marginal
survival fucntion at landmark information times, 0.25, 0.50, 0.75,
1.00, with each line showing median (MTE: marginal treatment effect)
its exponentiated value and its 95 percent credicble interval.
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
## Not run: my_coefs_cndl <- coef(my_bfhb) my_coefs_mgnl <- coef(update(my_bfhb, G_compute=TRUE)) ## End(Not run)## Not run: my_coefs_cndl <- coef(my_bfhb) my_coefs_mgnl <- coef(update(my_bfhb, G_compute=TRUE)) ## End(Not run)
Combines two survival/hazard plots side by side or two TrtEff density plots atop one another.
Combine(p1, p2, lgnd = NULL)Combine(p1, p2, lgnd = NULL)
p1 |
First plot |
p2 |
Second plot |
lgnd |
For the side by side hazard/survival plots the default is that one is conditional and one is marginal. If your use case is different, then put a legend consisting of two character strings to label the plots from left to right. See examples. |
Experimental at this stage.
A ggplot2 object
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
plot.BayesFBHborrow, BayesFBHborrow
## Not run: p_haz_nb_wb <- Combine(p_haz_nb, p_haz_wb) p_gbcs_TrtEff <- Combine(p_gbcs_nb_TrtEff, p_gbcs_wb_TrtEff, lgnd=c("NB","WB")) ## End(Not run)## Not run: p_haz_nb_wb <- Combine(p_haz_nb, p_haz_wb) p_gbcs_TrtEff <- Combine(p_gbcs_nb_TrtEff, p_gbcs_wb_TrtEff, lgnd=c("NB","WB")) ## End(Not run)
Data genereration to simultaneously generate from a proportional hazards Weibull model, two datasets, one to take the role as the current trial and the other to take the role as the historical controls.
genBFBHBdat(n_cc_1, n_cc_0, n_hst, B_trt, B_x_cc, int_cc, B_x_hst, int_hst, X_fact_levs = NULL, shape = 1, t_er, t_fin, dbg = FALSE)genBFBHBdat(n_cc_1, n_cc_0, n_hst, B_trt, B_x_cc, int_cc, B_x_hst, int_hst, X_fact_levs = NULL, shape = 1, t_er, t_fin, dbg = FALSE)
n_cc_1 |
Size of treated arm in current trial. |
n_cc_0 |
Size of control arm in current trial. |
n_hst |
Size of historical controls dataset. |
B_trt |
Treatment effect (logged hazard ratio). |
B_x_cc |
Coefficients (logged hazard ratio per unit) for effect of
pretreatment covariates in current trial. The leading end of the
vector specifies continuous covariates and the tail end of the
vector specifies coefficients for levels of factor variables. See
|
int_cc |
Intercept for current trial model. |
B_x_hst |
Coefficients (logged hazard ratio per unit) for effect of pretreatment covariates in historical coontrols. See X_fact_levs. |
int_hst |
Intercept for historical control model. |
X_fact_levs |
A numeric vector of length 'k' which specifies both the number, 'k',
of factor variables among the list of pre-treatment covariates, and
the number of levels of each factor variable in their components.
For example if we desire 3 continous variables and two factor
variables having 3 levels and 4 levels, then the coefficient vectors
described above |
shape |
The shape parameter for the Weibull distribution–currently the same for the current trial and historical controls. |
t_er |
The time at which randomization ends for use in administrative censoring for both the current trial and historical controls. |
t_fin |
The time of maximum follow-up for use in administrative censoring for both the current trial and historical controls. |
dbg |
If run at the command line, set |
A list of two component data.frames, DAT_cc and DAT_hst,
the current trial and the historical controls. Both current trial and
historical controls set have time to event and event indicator and any
pretreatment covariates specified via the arguments B_x_ and
X_fact_levs. In addition the current trial, DAT_cc, has
a treatment indicator. Variables in the data.frames are named as
follows.
tte |
Time to event, both data.frames. |
event |
Event indicator, both data.frames. |
X_trt |
Treatment indicator, current trial only. |
X_01...X_m |
Pre-treatment covariates both data.frames. |
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst)n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst)
Aggregate individual level data into group level data
group_summary(Y, I, X, s)group_summary(Y, I, X, s)
Y |
data |
I |
censoring indicator |
X |
design matrix |
s |
split points, J + 2 |
list of group level data
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
set.seed(111) ## simulate an example data and set your initial values and hyper parameters n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) ## Say we want to know the group level data for the following split points s <- with(DAT_cc, quantile(tte, c(0, 0.45, 0.65, 1), names = FALSE)) with(DAT_cc, group_summary(tte, event, X_trt, s))set.seed(111) ## simulate an example data and set your initial values and hyper parameters n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) ## Say we want to know the group level data for the following split points s <- with(DAT_cc, quantile(tte, c(0, 0.45, 0.65, 1), names = FALSE)) with(DAT_cc, group_summary(tte, event, X_trt, s))
Historical controls data extractor for object of class BFBHBdat as returned by the simulation routine genBFBHBdat.
historical_data(x)historical_data(x)
x |
An object of class BFBHdat as returned by the simulation routine genBFBHBdat |
The historical controls data.frame with variables
tte |
Time to event |
evnet |
Event indicator |
X_01 ... X_0n |
Pre-treatment covariates as directed in the call to genBFBHBdat |
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst)n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst)
Propose lambda hyperparameters for the choice of initial values for lambda
init_lambda_hyperparameters(group_data, s, w = 0.5)init_lambda_hyperparameters(group_data, s, w = 0.5)
group_data |
group level data |
s |
split points |
w |
weight |
shape and rate for the estimated lambda distribution
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
set.seed(111) ## simulate an example data and set your initial values and hyper parameters n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) ## Say we want to know the group level data for the following split points s <- with(DAT_cc, quantile(tte, c(0, 0.45, 0.65, 1), names = FALSE)) grpd_data <- with(DAT_cc, group_summary(tte, event, NULL, s)) init_lambda_hyperparameters(grpd_data, s)set.seed(111) ## simulate an example data and set your initial values and hyper parameters n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) ## Say we want to know the group level data for the following split points s <- with(DAT_cc, quantile(tte, c(0, 0.45, 0.65, 1), names = FALSE)) grpd_data <- with(DAT_cc, group_summary(tte, event, NULL, s)) init_lambda_hyperparameters(grpd_data, s)
Marginal Treatment Effect Extractor. Works on any BayesFBHborrow object having one or more pretreatment covariates.
MTE(object, ...)MTE(object, ...)
object |
an object of class BayesFBHborrow e.g. result of the main method. |
... |
other arguments for the update method |
A table (data.frame) showing the marginal treatment at 25%, 50%, 75% and 100%
InfFrac |
Information fraction: portion of total events observed 0.25, 0.50, 0.75 and 1.00 defining landmark times at which the marginal treament effect is calculated. |
Time |
The landmark times at which the indicated information fractions are attained. |
MTE |
The calculated marginal treatment effect, e.g. the difference of arm specific logged negative logged marginal survival functions; on the scale of logged relative risk |
exp(MTE) |
Exponentiated marginal treatment effect; on the scale of relative risk. |
MTE_L |
The lower bound of the 95% credible interval for MTE. |
MTE_U |
The upper bound of the 95% credible interval for MTE. |
Darrent Scott; Sophia Axillus and Grant Izmirlian
The plot method for the BayesFBHborrow class which allows quick convenient plots of important model summaries.
## S3 method for class 'BayesFBHborrow' plot(x, type = c("survival", "cumulative hazard", "hazard", "trace", "TrtEff"), col = NULL, InfFrac = NULL, ylim = NULL, ...)## S3 method for class 'BayesFBHborrow' plot(x, type = c("survival", "cumulative hazard", "hazard", "trace", "TrtEff"), col = NULL, InfFrac = NULL, ylim = NULL, ...)
x |
An object of class |
type |
The type of plot desired. Can be one of the following "survival", "cumulative hazard", "hazard", "trace", "TrtEff". |
col |
When |
InfFrac |
When |
ylim |
Sometimes in |
... |
Additional arguments to generic plot function |
A ggplot2 object.
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
## Not run: p_haz_wb <- plot(fit_sim_wb, type="hazard") p_gbcs_wb_trace <- plot(fit_gbcs_wb, type="trace", col="tamoxifen") p_gbcs_wb_TrtEff <- plot(fit_gbcs_wb, type="TrtEff") p_gbcs_wb_TrtEff_mgnl <- plot(update(fit_gbcs_wb, G_compute=TRUE), type="TrtEff") p_gbcs_wb_TrtEff_mgnl_75 <- plot(update(fit_gbcs_wb, G_compute=TRUE), type="TrtEff", InfFrac=0.75) ## End(Not run)## Not run: p_haz_wb <- plot(fit_sim_wb, type="hazard") p_gbcs_wb_trace <- plot(fit_gbcs_wb, type="trace", col="tamoxifen") p_gbcs_wb_TrtEff <- plot(fit_gbcs_wb, type="TrtEff") p_gbcs_wb_TrtEff_mgnl <- plot(update(fit_gbcs_wb, G_compute=TRUE), type="TrtEff") p_gbcs_wb_TrtEff_mgnl_75 <- plot(update(fit_gbcs_wb, G_compute=TRUE), type="TrtEff", InfFrac=0.75) ## End(Not run)
Reads in fine mesh grid conditional baseline hazard and arm specific marginal hazards of MCMC samples from the posterior that were written out sample at a time during iteration.
read_haz_mcmc_smpls(obj)read_haz_mcmc_smpls(obj)
obj |
An object of class |
MCMC samples of the baseline hazard are natively represented as number
of split-points, location of split-points and corresponding values of
the piecewise hazards. However the gibbs/MH updating done internally
invovles integrals over the time to event CDF is done with respect to
a fine mesh grid. Thus all iter samples must be snapped to a
common fine mesh grid of length max_grid. Row by row updates of
this matrix within iterations of the sampler is impractical based upon
the way R handles updating arrays involving multiple copies of it and
persistence of this memory usage within a loop until completion. This
will quickly consume free memory resulting in diskcaching and
ultimately machine freeze. For this reason binary file writes, per
iteration of the sampling loop, are done for the snapped to grid
versions of the following fucntions: the control arm conditional hazard,
conditional cumulative hazard, arm specific logged negative logged
marginal survival functions for which the difference is the marginal
treatment effect as a function of time, and the marginal hazards,
computed as the finite difference quotient of the their exponentiated
values. These files are then read back in after the sampling loop
for the summarization step. The corresponding six file names in
order given above are: cnd_haz_0_*.bin, cnd_cumHz0_*.bin,
lml_mgnl_surv_0_*.bin, lml_mgnl_surv_1_*.bin,
mgnl_haz_0_*.bin, and _mgnl_haz_1_*.bin. The default
behavior is to delete them when the main routine,
BayesFBHborrow, exits. However, if the user wishes to use them
in downstream calculation of functionals of the posterior distribution
of these quantities, the argument keep_binary_files should be
set to TRUE. Then one calls this function with the single
argument object, the result of BayesFBHborrow.
The names of the binary files associated with a given result are
returned with the object.
A list with components
cnd_haz_0 |
samples of the conditional baseline hazard
posterior as |
mgnl_haz_0 |
samples of the marginal control arm hazard
posterior as |
mgnl_haz_1 |
samples of the marginal treated arm hazard
posterior as |
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
## Not run: read_haz_mcmc_smpls(fit_my_bfbhb) ## End(Not run)## Not run: read_haz_mcmc_smpls(fit_my_bfbhb) ## End(Not run)
Calculates an ad-hoc relative efficiency for a model with and without borrowing, both being fitted BayesFBHborrow models. This is done by computing the squared ratio of the widths of their 95% credible intervals about the estimated treatment effect.
rel_eff(wb, nb, G_compute = FALSE)rel_eff(wb, nb, G_compute = FALSE)
wb |
A fitted BayesFBHborrow model, with borrowing |
nb |
The same fitted BayesFBHborrow model, without borrowing |
G_compute |
If |
A double precision numeric.
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Summary method for the BayesFBHborrow class
## S3 method for class 'BayesFBHborrow' summary(object, ...)## S3 method for class 'BayesFBHborrow' summary(object, ...)
object |
An object of class |
... |
Additional arguments to generic summary |
Every call to the function runs the sampler and then produces the
conditional estimand and marginal contrast for the
treatment/pretreatment variable effects. The argument G_compute
in the BayesFBHborrow call tells the print, plot, summary and
coef methods which version the user wants displayed.
The result of the summary method is an object of class
BayesFBHborrow identical to the input with the addition of two
new components – the ones shown by the print method.
coefficients |
If the original model involved p pre-treatment covariates and a treatment indicator, this will be a 2p + 1 by 4 matrix showing median of the logged hazard ratio, its exponentiated value and its 95 percent credible interval. |
surv_summary |
Shows arm specific conditional or A 8 by 6 matrix showing arm label C/I, information fraction Description of 'comp2' |
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) my_bfbhb <- BayesFBHborrow(Surv(tte, event) ~ X_trt + X_01 + X_02 + X_03, data = DAT_cc, data_hist = DAT_hst, model_choice = 'mix', iter = 10, warmup_iter = 5, refresh = 0, verbose = FALSE) my_bfbhb.s <- summary(my_bfbhb) my_bfbhb.sn_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst) my_bfbhb <- BayesFBHborrow(Surv(tte, event) ~ X_trt + X_01 + X_02 + X_03, data = DAT_cc, data_hist = DAT_hst, model_choice = 'mix', iter = 10, warmup_iter = 5, refresh = 0, verbose = FALSE) my_bfbhb.s <- summary(my_bfbhb) my_bfbhb.s
Current trial data extractor for object of class BFBHBdat as returned by the simulation routine genBFBHBdat.
trial_data(x)trial_data(x)
x |
An object of class BFBHdat as returned by the simulation routine genBFBHBdat |
The current trial data.frame with variables
tte |
Time to event |
evnet |
Event indicator |
X_trt |
Treatment indicator |
X_01 ... X_0n |
Pre-treatment covariates as directed in the call to genBFBHBdat |
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst)n_cc_1 <- 200 n_cc_0 <- 100 n_hst <- 100 int_cc <- int_hst <- -log(3) B_x_cc <- B_x_hst <- c(-0.3,0.5,0.25,-0.5) B_trt <- log(0.55) dat_lst <- genBFBHBdat(n_cc_1=200, n_cc_0=100, n_hst=100, B_trt=B_trt, B_x_cc=B_x_cc, B_x_hst=B_x_hst, int_cc=int_cc, int_hst=int_hst, shape=2, t_er=0.5, t_fin=1.5, X_fact_levs=3) DAT_cc <- trial_data(dat_lst) DAT_hst <- historical_data(dat_lst)
BayesFBHborrow Class
The Update Method for the BayesFBHborrow Class
## S3 method for class 'BayesFBHborrow' update( object, formula = NULL, data, data_hist = NULL, subset, na.action, CntlOnly = FALSE, model_choice = "mix", tuning_parameters = NULL, hyperparameters = NULL, iter = 1000, warmup_iter = 100, refresh = 0, verbose = FALSE, max_grid = 2000, standardise = TRUE, G_compute = FALSE, preprocess = TRUE, fnm_cnd_haz_0 = "cnd_haz_0", fnm_cnd_cumHz_0 = "cnd_cumHz_0", fnm_lml_mgnl_surv_0 = "lml_mgnl_surv_0", fnm_lml_mgnl_surv_1 = "lml_mgnl_surv_1", fnm_mgnl_haz_0 = "mgnl_haz_0", fnm_mgnl_haz_1 = "mgnl_haz_1", sfx = NULL, keep_bin_files= FALSE, n_chains = 1L, hpc_max_cores = 16, dbg = FALSE, evaluate = TRUE, ...)## S3 method for class 'BayesFBHborrow' update( object, formula = NULL, data, data_hist = NULL, subset, na.action, CntlOnly = FALSE, model_choice = "mix", tuning_parameters = NULL, hyperparameters = NULL, iter = 1000, warmup_iter = 100, refresh = 0, verbose = FALSE, max_grid = 2000, standardise = TRUE, G_compute = FALSE, preprocess = TRUE, fnm_cnd_haz_0 = "cnd_haz_0", fnm_cnd_cumHz_0 = "cnd_cumHz_0", fnm_lml_mgnl_surv_0 = "lml_mgnl_surv_0", fnm_lml_mgnl_surv_1 = "lml_mgnl_surv_1", fnm_mgnl_haz_0 = "mgnl_haz_0", fnm_mgnl_haz_1 = "mgnl_haz_1", sfx = NULL, keep_bin_files= FALSE, n_chains = 1L, hpc_max_cores = 16, dbg = FALSE, evaluate = TRUE, ...)
object |
An object of class |
formula |
Optional but most likely preferred. When using the formula/data interface, specify the formula in the form typically used in other survival models e.g. Surv(TOS, Event) ~ Trt + Oth + Covs + etc The first listed covariate must be the treatment variable. The rest can be continuous or factor. |
data |
Required. The current trial/study data.frame with a treated and a control arm. For the formula/data interface, there is no naming convention for variables as the user specifies these with the formula. For the data only interface, you must name the time to event variable 'tte', and the event variable 'event'. All covariates including the treatment indicator must have the 'X_' prefix. |
data_hist |
When fitting the full model with borrowing, the historical controls data.frame with variables named to agree with the current trial data.frame specified in the 'data' argument. Comments above regarding the formula/data versus data only interface apply here as well. |
subset |
When using the formula/data interface, you may also use
|
na.action |
When using the formula/data interface, you may also use
|
CntlOnly |
Set to |
model_choice |
Borrowing method. Determine the borrowing per split point by specifying the option "mix" (default) for a mixture of inverse gamma densities or "uni" for a single inverse gamma density. Otherwise, determine the borrowing once for all split points by specifying the option "all". |
tuning_parameters |
list with components |
hyperparameters |
list with components |
iter |
Number of iterations for MCMC sampler. |
warmup_iter |
Number of warmup iterations (burn-in) for MCMC sampler. |
refresh |
Number of iterations between printed screen updates. |
verbose |
Whether or not to print the progress to the console
every |
max_grid |
Grid size for the smoothed baseline hazard. Default value is 2000. |
standardise |
Whether or not to normalize the current trial baseline hazard to
unity and apply the same normalization constant to the historical
data. Default is |
G_compute |
If set to |
preprocess |
Controls the interpretation of the 'baseline' hazard consequent to
recoding of the input dataset(s). When set to |
fnm_cnd_haz_0 |
name prefix with a random hex suffix. The collection of
"snapped to common grid" samples from the posterior distribution of
the baseline hazards is a matrix of dimension |
fnm_cnd_cumHz_0 |
(see above) This file contains samples of the conditional baseline cumulative hazard. |
fnm_lml_mgnl_surv_0 |
(see above) This file contains samples of the logged negative logged control arm marginal survival function. |
fnm_lml_mgnl_surv_1 |
(see above) This file contains samples of the logged negative logged treated arm marginal survival function. |
fnm_mgnl_haz_0 |
(see above) This file contains samples of the control arm marginal hazard which have been derived as the finite difference quotient of the exponentiated values in the lml_mgnl_surv_0 file. |
fnm_mgnl_haz_1 |
(see above) This file contains samples of the treated arm marginal hazard which have been derived as the finite difference quotient of the exponentiated values in the lml_mgnl_surv_0 file. |
sfx |
The name of the subdirectory created in the current working directory to contain these binary files. Also used in the suffix of the file names. The default behavior is to give this a random 6 digit hex string so there's no need to specify this argument either. |
keep_bin_files |
Defaults to |
n_chains |
Number of chains to sample in parallel post warmup. This is determined automatically by the function depending on the capabilities of your machine and the OS you are using (unix alike [mac/WSL], HPC cluster, or windows). No need to set this |
hpc_max_cores |
If you use the HPC cluster either in the workbench or setting up an interactive node the command line you should request 'Rstudio large' and then set the number of cores to anything up to 32. You should request 16GB of ram so you might have to play with setting until you're given permission to open the session. At AZ I've had success with 16GB and 16 cores. In any case, set this to the number of cores you're able to get. |
dbg |
When running in command line mode, set to |
evaluate |
controls whether the modified model call is executed immediately or just returned as an expressionaluate |
... |
Other arguments as needed. |
Note that the marginal contrast is always computed in addition to the
conditional estimand. If G_compute=FALSE, (the default) in the
original call, the print, coef, summary and plot methods will
produce results reflecting the conditional estimand, whereas these
will reflect the marginal contrast otherwise. NOTE: calling
update(my_bfbhb, G_compute=TRUE) doesn't require rerunning the
sampler as the results are already there.
An object of class BayesFBHborrow. See the documentation.
Darren A. V. Scott, Sophia Axillus and Grant Izmirlian
Scott D.A.V. and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott D.A.V., Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
plot, summary, update methods for class
"BayesFBHborrow" objects
## Not run: update(my_bfbhb, G_compute=TRUE) ## End(Not run)## Not run: update(my_bfbhb, G_compute=TRUE) ## End(Not run)
Finds the value of the root (in the interval [0, 2]) for the function p0tp involving mixture probability p_0 and hyperparameters b_tau and d_tau.
xifinder(b_tau, d_tau, p_0)xifinder(b_tau, d_tau, p_0)
b_tau |
Shape (or scale) parameter for the first mixture component. |
d_tau |
Shape (or scale) parameter for the second mixture component. |
p_0 |
Mixture proportion; probability for the first component, in (0, 1). |
Uses uniroot() to numerically solve for the root of the function p0tp on the interval [0, 2]. The function p0tp should accept arguments x, b_tau, d_tau, and p_0. This is typically used for calibrating the mixture prior or solving for a relevant quantile in hierarchical Bayesian models.
Note: The auxiliary function p0tp must be defined in the environment.
Numeric value; the root of the p0tp equation within the interval.
Scott DAV and Lewin A (2026). Borrowing from historical control data in a Bayesian time-to-event model with flexible baseline hazard function. Biostatistics 27(1)
Scott DAV, Axillus S, Lewin A and Izmirlian G. BayesFBHborrow: An R Package for Bayesian borrowing for time-to-event data from a flexible baseline hazard function (2026) <doi:10.48550/arXiv.2408.04327>
plot, summary, update methods for class
"BayesFBHborrow" objects
## Suppose p0tp is defined elsewhere ## Find a root for specific parameters: xifinder(b_tau = 0.1, d_tau = 1, p_0 = 0.75)## Suppose p0tp is defined elsewhere ## Find a root for specific parameters: xifinder(b_tau = 0.1, d_tau = 1, p_0 = 0.75)