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()$get_output()$reset()
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 before running
additional replicate of simulation. This is usually done between two
calls of controller$run().
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.
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.dry_runlogical. We are considering retire this argument.
TRUEif action function provided by users is ignored and an internal default action.default_actionis called instead. This default function only locks data when the milestone is triggered. Milestone time and number of endpoints' events or sample sizes are saved. It is suggested to setdry_run = TRUEto estimate distributions of triggering time and number of events before formally using custom action functions if a fixed design is in use. This helps determining planned maximum information for group sequential design and reasonable time of milestone of interest when planning a trial. Set it toFALSEfor formal simulations. However, for an adaptive design where arm(s) could possibly be added or removed, settingdry_runtoTRUEis usually not helpful because adaption should be executed before estimating the milestone time.
