Timer: Track timed events across arms
Timer.RdA class to collect and query timepoints - time-based enrollment and dropout events - across trial arms.
Use add_schedule() to register events and
get_end_timepoint() / get_n_arms() / get_unique_times() for
summary queries. The full event table is the public timelist field.
Details
Trigger conditions (filtering + analysis) are now managed by the separate
Condition class. Condition objects are stored in trial$conditions
and evaluated by Trial$run() at each timepoint.
Helper functions condition_calendar_time() and condition_enrollment_fraction()
provide convenient shortcuts for building Condition objects; both return
a Condition that you pass to Trial$new(conditions = list(...)).
See also
Trial to coordinate simulations with populations,
Condition for trigger/analysis logic,
stochastic_schedule() / deterministic_schedule() to build a schedule.
Public fields
namecharacterUnique identifier for theTimerinstance.timelistdata.frameA data.frame of timepoints with columns:timenumericCalendar timearmcharacterUnique identifier of the armdropinteger# of subjects dropped attimeenrollinteger# of subjects enrolled attime
Methods
Timer$new()
Create a new Timer instance.
Usage
Timer$new(name, timelist = NULL)Arguments
namecharacterUnique identifier.timelistdata.frameOptional data.frame of timepoints with columnstime,arm,drop,enroll. IfNULL, an empty frame is created.
Examples
t <- Timer$new(name = "Timer")Timer$add_schedule()
Add a schedule of timepoints to the timer.
Arguments
scheduledata.framewith columnstime(numeric),arm(character),enroll(integer),drop(integer). One row per event; a single event is a one-row data frame. Typically the output ofstochastic_schedule()ordeterministic_schedule().enrollanddropare subject counts and must be integer (3L, not3) - fractional counts are silently truncated downstream, so they are rejected here.
Examples
t <- Timer$new(name = "Timer")
# single event
t$add_schedule(data.frame(time = 1, arm = "A", drop = 1L, enroll = 3L))
# whole schedule (data.frame() recycles the constant columns)
t$add_schedule(data.frame(time = 2:3, arm = "A", enroll = 2L, drop = 0L))Timer$get_end_timepoint()
Determine the last timepoint for a given instance of Timer class.
Examples
t <- Timer$new(name = "Timer")
t$add_schedule(data.frame(time = 3.14, arm = "A", drop = 7L, enroll = 22L))
t$get_end_timepoint()Timer$get_n_arms()
Get number of unique arms.
Examples
t <- Timer$new(name = "Timer")
t$add_schedule(data.frame(time = 3.14, arm = "A", drop = 7L, enroll = 22L))
t$add_schedule(data.frame(time = 3.28, arm = "B", drop = 6L, enroll = 23L))
t$get_n_arms()Timer$get_unique_times()
Get unique timepoints.
Examples
t <- Timer$new(name = "Timer")
t$add_schedule(data.frame(time = 3.14, arm = "A", drop = 7L, enroll = 22L))
t$add_schedule(data.frame(time = 3.28, arm = "B", drop = 6L, enroll = 23L))
t$get_unique_times()Examples
# Basic construction
t <- Timer$new(name = "Timer")
# Add timepoints
t$add_schedule(data.frame(
time = c(1, 2, 1),
arm = c("A", "A", "B"),
drop = c(2L, 1L, 0L),
enroll = c(10L, 12L, 8L)
))
# Query
t$get_end_timepoint() # max time => 2
#> [1] 2
t$get_n_arms() # unique arms => 2
#> [1] 2
t$get_unique_times() # unique times => c(1, 2)
#> [1] 1 2
t$timelist # the full event table
#> time arm drop enroll
#> 1 1 A 2 10
#> 2 2 A 1 12
#> 3 1 B 0 8
## ------------------------------------------------
## Method `Timer$new()`
## ------------------------------------------------
t <- Timer$new(name = "Timer")
## ------------------------------------------------
## Method `Timer$add_schedule()`
## ------------------------------------------------
t <- Timer$new(name = "Timer")
# single event
t$add_schedule(data.frame(time = 1, arm = "A", drop = 1L, enroll = 3L))
# whole schedule (data.frame() recycles the constant columns)
t$add_schedule(data.frame(time = 2:3, arm = "A", enroll = 2L, drop = 0L))
## ------------------------------------------------
## Method `Timer$get_end_timepoint()`
## ------------------------------------------------
t <- Timer$new(name = "Timer")
t$add_schedule(data.frame(time = 3.14, arm = "A", drop = 7L, enroll = 22L))
t$get_end_timepoint()
#> [1] 3.14
## ------------------------------------------------
## Method `Timer$get_n_arms()`
## ------------------------------------------------
t <- Timer$new(name = "Timer")
t$add_schedule(data.frame(time = 3.14, arm = "A", drop = 7L, enroll = 22L))
t$add_schedule(data.frame(time = 3.28, arm = "B", drop = 6L, enroll = 23L))
t$get_n_arms()
#> [1] 2
## ------------------------------------------------
## Method `Timer$get_unique_times()`
## ------------------------------------------------
t <- Timer$new(name = "Timer")
t$add_schedule(data.frame(time = 3.14, arm = "A", drop = 7L, enroll = 22L))
t$add_schedule(data.frame(time = 3.28, arm = "B", drop = 6L, enroll = 23L))
t$get_unique_times()
#> [1] 3.14 3.28