Author: Kevin R. Coombes and Caitlin E. Coombes

# Umpire 2.0: Simulating Associated Survival

#### Kevin R. Coombes and Caitlin E. Coombes

Load the packages we need.

    library(Umpire)
    library(survival)

# Base Survival

Create a survival model, and generate data.

    sm <- SurvivalModel(baseHazard = 1/5, # default 1/5 inverse years
                        accrual = 5,      # default 5 years
                        followUp = 1,     # default 1 years
                        units = 12, unitName = "months")
    R <- rand(sm, 200)
    summary(R)

    ##       LFU          Event
    ##  Min.   : 0.00   Mode :logical
    ##  1st Qu.:14.75   FALSE:101
    ##  Median :28.00   TRUE :99
    ##  Mean   :29.25
    ##  3rd Qu.:41.00
    ##  Max.   :70.00

Fit a Kaplan-Meier curve.

    baseModel <- survfit(Surv(LFU, Event) ~ 1, R)
    plot(baseModel)

Base Kaplan-Meier survival curve.

## Default method to generate beta coefficients.

Now create several cancer models and generate data.

    for (ignore in 1:5) {
      for (jgnore in 1:4) {
        cm <- CancerModel("survtester", nPossible=20, nPattern=2,
                           SURV = function(n) rnorm(n, 0, 2), # old default; too large
                       survivalModel = sm)
        S <- rand(cm, 200)
        model <- survfit(Surv(LFU, Event) ~ CancerSubType, S)
        print(model)
        plot(model)
      }
    }

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  90      9     NA      NA      NA
    ## CancerSubType=2 110    101      8       6       9

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  98      5     NA      NA      NA
    ## CancerSubType=2 102      0     NA      NA      NA

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 101    101      0      NA      NA
    ## CancerSubType=2  99     94      7       5      10

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 103     95      6       5      11
    ## CancerSubType=2  97     97      0       0       0

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  94     81     13      11      19
    ## CancerSubType=2 106     88     12      10      17

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  94     94      1       1       2
    ## CancerSubType=2 106      0     NA      NA      NA

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 101     48     43      30      NA
    ## CancerSubType=2  99     72     22      18      30

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  89      2     NA      NA      NA
    ## CancerSubType=2 111     90     15      11      19

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 100    100      0       0       0
    ## CancerSubType=2 100      0     NA      NA      NA

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 101     12     NA      NA      NA
    ## CancerSubType=2  99     99      0       0       0

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  97      0     NA      NA      NA
    ## CancerSubType=2 103     53     34      27      53

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 102      1     NA      NA      NA
    ## CancerSubType=2  98     93      5       4       6

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 103     98      7       5       9
    ## CancerSubType=2  97      3     NA      NA      NA

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 113     37     NA      64      NA
    ## CancerSubType=2  87     87      1       0       2

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 117      1     NA      NA      NA
    ## CancerSubType=2  83     83      1       1       2

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 103    102      2       2       3
    ## CancerSubType=2  97     12     NA      NA      NA

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 105     18     NA      NA      NA
    ## CancerSubType=2  95     27     NA      57      NA

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  93      4     NA      NA      NA
    ## CancerSubType=2 107     89     15      12      17

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  88     72     11       7      19
    ## CancerSubType=2 112    111      3       2       4

Two group survival curves (original).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 108    108      0       0       0
    ## CancerSubType=2  92     92      0      NA      NA

Two group survival curves (original).

## Better method to generate beta coefficients.

Now create several cancer models and generate data.

    for (ignore in 1:5) {
      for (jgnore in 1:4) {
        cm <- CancerModel("survtester", nPossible=20, nPattern=2,
                           SURV = function(n) rnorm(n, 0, 0.3),
                       survivalModel = sm)
        S <- rand(cm, 200)
        model <- survfit(Surv(LFU, Event) ~ CancerSubType, S)
        print(model)
        plot(model)
      }
    }

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  92     40     45      41      NA
    ## CancerSubType=2 108     62     34      27      42

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  89     29     NA      59      NA
    ## CancerSubType=2 111     46     51      39      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  94     35     NA      47      NA
    ## CancerSubType=2 106     39     62      52      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 111     89     17      13      22
    ## CancerSubType=2  89     63     25      15      33

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 102     22     NA      NA      NA
    ## CancerSubType=2  98     78     15      11      22

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  78     54     15      11      22
    ## CancerSubType=2 122     70     28      21      44

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  98     34     NA      41      NA
    ## CancerSubType=2 102     28     NA      57      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  95     43     51      31      NA
    ## CancerSubType=2 105     63     28      22      45

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  98     19     NA      NA      NA
    ## CancerSubType=2 102     29     NA      55      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  97     56     32      27      46
    ## CancerSubType=2 103     37     56      47      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  94     60     26      18      36
    ## CancerSubType=2 106     52     43      23      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 100      5     NA      NA      NA
    ## CancerSubType=2 100     41     54      41      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 106     40     61      48      NA
    ## CancerSubType=2  94     31     68      56      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  96     46     34      27      NA
    ## CancerSubType=2 104     28     NA      56      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 111     87     16      12      21
    ## CancerSubType=2  89     41     40      36      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  96     55     26      20      55
    ## CancerSubType=2 104     53     42      27      56

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 107     65     36      24      46
    ## CancerSubType=2  93     24     63      57      NA

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  98     66     19      17      28
    ## CancerSubType=2 102     51     35      30      49

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  95     73     23      18      29
    ## CancerSubType=2 105     74     21      17      26

Two group survival curves (improved).

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 105     94     11       9      15
    ## CancerSubType=2  95     30     NA      56      NA

Two group survival curves (improved).

## Fewer possible hits

    for (nPos in c(5, 10, 15)) {
      for (jgnore in 1:4) {
        cm <- CancerModel("survtester", nPossible=nPos, nPattern=2,
                           SURV = function(n) rnorm(n, 0, 0.3),
                       survivalModel = sm)
        S <- rand(cm, 200)
        model <- survfit(Surv(LFU, Event) ~ CancerSubType, S)
        print(model)
        plot(model)
      }
    }

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  90     76     12      11      15
    ## CancerSubType=2 110     97     12       8      19

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 101     18     NA      NA      NA
    ## CancerSubType=2  99     19     NA      NA      NA

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  92     50     34      24      51
    ## CancerSubType=2 108     56     38      28      50

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  95     48     40      29      51
    ## CancerSubType=2 105     48     45      40      NA

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  99     14     NA      NA      NA
    ## CancerSubType=2 101     19     NA      61      NA

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  91     72     15      12      23
    ## CancerSubType=2 109     75     21      18      35

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  96     27     NA      50      NA
    ## CancerSubType=2 104     40     47      38      NA

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  99     47     39      30      NA
    ## CancerSubType=2 101     53     33      30      61

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 100     35     NA      45      NA
    ## CancerSubType=2 100     19     NA      NA      NA

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1 100     48     43      26      NA
    ## CancerSubType=2 100     53     31      23      NA

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  97     27     NA      62      NA
    ## CancerSubType=2 103     44     47      36      NA

    ## Call: survfit(formula = Surv(LFU, Event) ~ CancerSubType, data = S)
    ##
    ##                   n events median 0.95LCL 0.95UCL
    ## CancerSubType=1  98     33     NA      53      NA
    ## CancerSubType=2 102     24     NA      62      NA

# Appendix

    sessionInfo()

    ## R version 4.4.1 (2024-06-14 ucrt)
    ## Platform: x86_64-w64-mingw32/x64
    ## Running under: Windows 11 x64 (build 26100)
    ##
    ## Matrix products: default
    ##
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.utf8
    ## [3] LC_MONETARY=English_United States.utf8
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.utf8
    ##
    ## time zone: America/New_York
    ## tzcode source: internal
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] survival_3.6-4 Umpire_2.0.11
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] sass_0.4.9         utf8_1.2.4         generics_0.1.3     tidyr_1.3.1
    ##  [5] rstatix_0.7.2      lattice_0.22-6     digest_0.6.36      magrittr_2.0.3
    ##  [9] evaluate_0.24.0    grid_4.4.1         mvtnorm_1.2-5      fastmap_1.2.0
    ## [13] jsonlite_1.8.8     Matrix_1.7-0       backports_1.5.0    mclust_6.1.1
    ## [17] purrr_1.0.2        fansi_1.0.6        mc2d_0.2.1         BimodalIndex_1.1.9
    ## [21] scales_1.3.0       jquerylib_0.1.4    abind_1.4-5        cli_3.6.3
    ## [25] rlang_1.1.4        munsell_0.5.1      splines_4.4.1      cachem_1.1.0
    ## [29] yaml_2.3.10        tools_4.4.1        ggsignif_0.6.4     dplyr_1.1.4
    ## [33] colorspace_2.1-1   ggplot2_3.5.1      ggpubr_0.6.0       broom_1.0.6
    ## [37] vctrs_0.6.5        R6_2.5.1           lifecycle_1.0.4    car_3.1-2
    ## [41] oompaBase_3.2.9    cluster_2.1.6      pkgconfig_2.0.3    pillar_1.9.0
    ## [45] bslib_0.8.0        gtable_0.3.5       glue_1.7.0         xfun_0.46
    ## [49] tibble_3.2.1       tidyselect_1.2.1   highr_0.11         knitr_1.48
    ## [53] htmltools_0.5.8.1  rmarkdown_2.27     carData_3.0-5      compiler_4.4.1