Create a class of controller to run a trial.
Public methods in this R6 class are used in developing this package. Thus, we have to export the whole R6 class which exposures all public methods. However, only the public methods in the list below are useful to end users.
$run()run trial simulation, sequentially or in parallel. It cannot be called twice on a controller unless$reset()is called in between.$get_output()return a data frame of all outputs saved during simulation.$reset()reset the trial and listener registered to the controller before starting a new simulation with$run().
Value
an R6Class generator object; use controller() to create a controller.
Methods
Method new()
initialize a controller of the trial
Usage
Controllers$new(trial, listener)Arguments
triala trial object returned from
trial().listenera listener object returned from
listener().
Method reset()
reset the trial and listener registered to the controller so that a
new simulation can be started with controller$run(). The trial
and the milestones are restored to their as-designed version.
Method get_output()
return a data frame of all current outputs saved by calling save().
Arguments
colscharacter vector. Columns to be returned from the data frame of simulation outputs. If
NULL, all columns are returned.simplifylogical. Return vector rather than a data frame of one column when
length(cols) == 1andsimplify == TRUE.tidylogical.
TrialSimulatorautomatically records a set of standard outputs at milestones, even whendoNothingis used as action functions. These includes time of triggering milestones, number of observed events for time-to-event endpoints, and number of non-missing readouts for non-TTE endpoints (seevignette('actionFunctions')). This usually mean a large number of columns in outputs. If users have no intent to summarize a trial on these columns, settingtidy = TRUEcan eliminate these columns fromget_output(). This is useful to reduced the size of output data frame when a large number of replicates are done for simulation. Note that currently we use regex"^n_events_<.*?>_<.*?>$"and"^milestone_time_<.*?>$"to match columns to be eliminated. If users plan to usetidy = TRUE, caution is needed when naming custom outputs insave(). DefaultFALSE.
Method run()
run trial simulation. It cannot be called again on the same
controller unless reset() is called first.
Arguments
ninteger. Number of replicates of simulation.
n = 1by default. Simulation results can be accessed bycontroller$get_output().n_workersinteger. Number of parallel workers. When
n_workers = 1(default), replicates are run sequentially. Whenn_workers > 1, replicates are distributed across parallel workers using themiraipackage, which must be installed separately. Each worker receives a serialized copy of the trial and listener objects and runs its share of replicates independently. If any replicate encounters an error, execution stops and already-collected results are preserved in$get_output(). To debug, manually setseedintrial()andn_workers = 1inrun()for reproduced results. Note that optimaln_workersmay not beparallel::detectCores(). For example, Macbook with M1/M2/M3 chips may have performance cores and efficiency cores. To achieve the best parallel performance, one may want to use the performance cores only. For a M1 laptop with 4 performance cores,n_workers = 3may give the best performance.plot_eventlogical. Create event plot if
TRUE. Forced toFALSEwhenn > 1orn_workers > 1.silentlogical.
TRUEif muting all messages during a trial. Note that warning messages are still displayed. Whensilent = TRUEand replicates are run sequentially (n_workers = 1), a progress bar is displayed automatically if the simulation is expected to take more than 1 minute.tidylogical. If
TRUE, the per-arm event count table (output columnn_events_<milestone>_<arms>) is not saved at milestones; the per-endpoint totals and milestone times are still saved. Saving that table is the most expensive part of the standard outputs, sotidy = TRUEis recommended for a large number of replicates unless the per-arm counts are needed in the summary. This differs fromtidyin$get_output(), which removes all standard columns from the returned data frame after the fact. DefaultFALSE.