Learn R Programming

trialr (version 0.0.7)

peps2_run_sims: Run simulations of BEBOP in PePS2

Description

Run simulations of the BEBOP model in a PePS2 scenario. The logic of creating the data to be passed to the Stan model is delegated to a function, thus the user may tailor rates of efficacy and toxicity, priors, cohort membership probabilities, by specialising this function. Similarly, the post-processing to perform on the RStan sample is delegated to another function. This pattern gives a flexible interface.

Usage

peps2_run_sims(num_sims, sample_data_func, summarise_func, ...)

Arguments

num_sims

integer, number of simulated iterations

sample_data_func

delegate function that takes no parameters and returns a list like peps2_params. This function is called during each simulated iteration so it should contain random outcomes.

summarise_func

delegate function that takes args dat and fit, where dat is an instance of peps2_params returned by sample_data_func(), and fit is an instance of rstan::stanmodel, derived by sampling the BebopInPeps2 model. The simulation routine collects this using stan::sampling(stanmodels$BebopInPeps2, data = dat). The objects returned by this delegate are ultimately returned to the user. Thus, this function should perform the post-processing to get the RStan sample into some useful format. An example if peps2_process.

...

extra parameters passed to rstan::sampling.

Value

a list of length num_sims, with element i being the result of the ith call to summarise_func(dat, fit).

See Also

peps2_params

peps2_get_data

peps2_process

Examples

Run this code
# NOT RUN {
prob_eff <- c(0.167, 0.192, 0.5, 0.091, 0.156, 0.439)
prob_tox = c(0.1, 0.1, 0.1, 0.1, 0.1, 0.1)
peps2_scenario_data <- function() peps2_get_data(num_patients = 60,
                                                 prob_eff = prob_eff,
                                                 prob_tox = prob_tox,
                                                 eff_tox_or = rep(1, 6))
set.seed(123)
# }
# NOT RUN {
sims <- peps2_run_sims(num_sims = 10, sample_data_func = peps2_scenario_data,
                       summarise_func = peps2_process)
apply(sapply(sims, function(x) x$Accept), 1, mean)  # 0.5 0.7 1.0 0.2 0.5 1.0
# }
# NOT RUN {
# Simulation suggests we are likely to approve in cohorts 3 and 6.
# In real life, we would run thousands of iterations, not 10.
# This is an example.

# }

Run the code above in your browser using DataLab