This is similar to survSplit but allow the starting time and ending time to be equal (e.g., immediate death, automatic default in loan) and automatically include min and max of duration in the cut intervals

surv_split(
  x,
  duration,
  event,
  cuts,
  time_varying = NULL,
  label_episode = FALSE
)

Arguments

x

data frame

duration

exposure time

event

binary 0 and 1 coded

time_varying

not in use

label_episode

set to TRUE to have the episode labeled with actual cut intervals, otherwise episodes are integers

cut

the cut points on duration forming intervals [min_duration, first_value], (first_value, second_value], ..., (last_value, max_duration]

Details

The tested speed is 1.37 times to that of survSplit.

Examples

x <- data.frame(time = c(5, 10), event = c(1, 0))
surv_split(x, "time", "event", c(2,4,6))
#>     time event episode t_start t_end
#> 1      5     0       1       0     2
#> 1.1    5     0       2       2     4
#> 1.2    5     1       3       4     5
#> 2     10     0       1       0     2
#> 2.1   10     0       2       2     4
#> 2.2   10     0       3       4     6
#> 2.3   10     0       4       6    10
surv_split(x, "time", "event", c(2,4,6), label_episode = TRUE)
#>     time event episode t_start t_end
#> 1      5     0   [0,2]       0     2
#> 1.1    5     0   (2,4]       2     4
#> 1.2    5     1   (4,6]       4     5
#> 2     10     0   [0,2]       0     2
#> 2.1   10     0   (2,4]       2     4
#> 2.2   10     0   (4,6]       4     6
#> 2.3   10     0  (6,10]       6    10