This function extracts relevant information from multiple simulations of the
same trial specification in a tidy data.frame (1 simulation per row).
See also the check_performance() and summary() functions, that uses the
output from this function to further summarise simulation results.
Usage
extract_results(
object,
select_strategy = "control if available",
select_last_arm = FALSE,
select_preferences = NULL,
te_comp = NULL,
raw_ests = FALSE,
final_ests = NULL,
cores = NULL
)Arguments
- object
trial_resultsobject, output from therun_trials()function.- select_strategy
single character string. If a trial was not stopped due to superiority (or had only 1 arm remaining, if
select_last_armis set toTRUEin trial designs with a commoncontrolarm; see below), this parameter specifies which arm will be considered selected when calculating trial design performance metrics, as described below; this corresponds to the consequence of an inconclusive trial, i.e., which arm would then be used in practice.
The following options are available and must be written exactly as below (case sensitive, cannot be abbreviated):"control if available"(default): selects the firstcontrolarm for trials with a commoncontrolarm if this arm is active at end-of-trial, otherwise no arm will be selected. For trial designs without a commoncontrol, no arm will be selected."none": selects no arm in trials not ending with superiority."control": similar to"control if available", but will throw an error if used for trial designs without a commoncontrolarm."final control": selects the finalcontrolarm regardless of whether the trial was stopped for practical equivalence, futility, or at the maximum sample size; this strategy can only be specified for trial designs with a commoncontrolarm."control or best": selects the firstcontrolarm if still active at end-of-trial, otherwise selects the best remaining arm (defined as the remaining arm with the highest probability of being the best in the last adaptive analysis conducted). Only works for trial designs with a commoncontrolarm."best": selects the best remaining arm (as described under"control or best")."list or best": selects the first remaining arm from a specified list (specified usingselect_preferences, technically a character vector). If none of these arms are are active at end-of-trial, the best remaining arm will be selected (as described above)."list": as specified above, but if no arms on the provided list remain active at end-of-trial, no arm is selected.
- select_last_arm
single logical, defaults to
FALSE. IfTRUE, the only remaining active arm (the lastcontrol) will be selected in trials with a commoncontrolarm ending withequivalenceorfutility, before considering the options specified inselect_strategy. Must beFALSEfor trial designs without a commoncontrolarm.- select_preferences
character vector specifying a number of arms used for selection if one of the
"list or best"or"list"options are specified forselect_strategy. Can only contain validarmsavailable in the trial.- te_comp
character string, treatment-effect comparator. Can be either
NULL(the default) in which case the firstcontrolarm is used for trial designs with a common control arm, or a string naming a single trialarm. Will be used when calculatingerr_teandsq_err_te(the error and the squared error of the treatment effect comparing the selected arm to the comparator arm, as described below).- raw_ests
single logical. If
FALSE(default), the posterior estimates (post_estsorpost_ests_all, seesetup_trial()andrun_trial()) will be used to calculateerrandsq_err(the error and the squared error of the estimated compared to the specified effect in the selected arm) anderr_teandsq_err_te(the error and the squared error of the treatment effect comparing the selected arm to the comparator arm, as described forte_compand below). IfTRUE, the raw estimates (raw_estsorraw_ests_all, seesetup_trial()andrun_trial()) will be used instead of the posterior estimates.- final_ests
single logical. If
TRUE(recommended) the final estimates calculated using outcome data from all patients randomised when trials are stopped are used (post_ests_allorraw_ests_all, seesetup_trial()andrun_trial()); ifFALSE, the estimates calculated for each arm when an arm is stopped (or at the last adaptive analysis if not before) using data from patients having reach followed up at this time point and not all patients randomised are used (post_estsorraw_ests, seesetup_trial()andrun_trial()). IfNULL(the default), this argument will be set toFALSEif outcome data are available immediate after randomisation for all patients (for backwards compatibility, as final posterior estimates may vary slightly in this situation, even if using the same data); otherwise it will be said toTRUE. Seesetup_trial()for more details on how these estimates are calculated.- cores
NULLor single integer. IfNULL, a default value set bysetup_cluster()will be used to control whether extractions of simulation results are done in parallel on a default cluster or sequentially in the main process; if a value has not been specified bysetup_cluster(),coreswill then be set to the value stored in the global"mc.cores"option (if previously set byoptions(mc.cores = <number of cores>), and1if that option has not been specified.
Ifcores = 1, computations will be run sequentially in the primary process, and ifcores > 1, a new parallel cluster will be setup using theparallellibrary and removed once the function completes. Seesetup_cluster()for details.
Value
A data.frame containing the following columns:
sim: the simulation number (from1to the total number of simulations).final_n: the final sample size in each simulation.sum_ys: the sum of the total counts in all arms, e.g., the total number of events in trials with a binary outcome (setup_trial_binom()) or the sum of the arm totals in trials with a continuous outcome (setup_trial_norm()). Always uses all outcome data from all randomised patients regardless of whether or not all patients had outcome data available at the time of trial stopping (corresponding tosum_ys_allin results fromrun_trial()).ratio_ys: calculated assum_ys/final_n(as described above).final_status: the final trial status for each simulation, either"superiority","equivalence","futility", or"max", as described inrun_trial().superior_arm: the final superior arm in simulations stopped for superiority. Will beNAin simulations not stopped for superiority.selected_arm: the final selected arm (as described above). Will correspond to thesuperior_armin simulations stopped for superiority and beNAif no arm is selected. Seeselect_strategyabove.err: the squared error of the estimate in the selected arm, calculated asestimated effect - true effectfor the selected arm.sq_err:the squared error of the estimate in the selected arm, calculated aserr^2for the selected arm, witherrdefined above.err_te: the error of the treatment effect comparing the selected arm to the comparator arm (as specified inte_comp). Calculated as:(estimated effect in the selected arm - estimated effect in the comparator arm) -(true effect in the selected arm - true effect in the comparator arm)
Will beNAfor simulations without a selected arm, with no comparator specified (seete_compabove), and when the selected arm is the comparator arm.sq_err_te: the squared error of the treatment effect comparing the selected arm to the comparator arm (as specified inte_comp), calculated aserr_te^2, witherr_tedefined above.
Examples
# Setup a trial specification
binom_trial <- setup_trial_binom(arms = c("A", "B", "C", "D"),
control = "A",
true_ys = c(0.20, 0.18, 0.22, 0.24),
data_looks = 1:20 * 100)
# Run 10 simulations with a specified random base seed
res <- run_trials(binom_trial, n_rep = 10, base_seed = 12345)
# Extract results and Select the control arm if available
# in simulations not ending with superiority
extract_results(res, select_strategy = "control")
#> sim final_n sum_ys ratio_ys final_status superior_arm selected_arm
#> 1 1 2000 387 0.1935 max <NA> A
#> 2 2 2000 391 0.1955 max <NA> A
#> 3 3 2000 359 0.1795 max <NA> <NA>
#> 4 4 2000 389 0.1945 max <NA> A
#> 5 5 2000 373 0.1865 max <NA> A
#> 6 6 400 84 0.2100 superiority B B
#> 7 7 2000 395 0.1975 max <NA> A
#> 8 8 2000 442 0.2210 max <NA> A
#> 9 9 2000 413 0.2065 max <NA> A
#> 10 10 2000 466 0.2330 max <NA> A
#> err sq_err err_te sq_err_te
#> 1 0.027072360 7.329127e-04 NA NA
#> 2 0.027225919 7.412507e-04 NA NA
#> 3 NA NA NA NA
#> 4 0.028619492 8.190753e-04 NA NA
#> 5 -0.014477338 2.095933e-04 NA NA
#> 6 -0.022699865 5.152839e-04 -0.1820624 0.0331467
#> 7 0.009098866 8.278937e-05 NA NA
#> 8 0.010663973 1.137203e-04 NA NA
#> 9 0.015544164 2.416210e-04 NA NA
#> 10 0.019152691 3.668256e-04 NA NA