Author: Wenqing Zhang

# Example Analysis using jointCompRisk

#### Wenqing Zhang

### Part I: CIF Inference

    raw <- read.csv("main_df.csv")
    long <- read.csv("long_df.csv")

    # 1) Standard CIF:
    mydata_std <- prep_data_cif(
      data             = raw,
      ID               = "ID",
      TimeToRecovery   = "TimeToRecovery",
      TimeToDeath      = "TimeToDeath",
      Recov_Censoring  = "RecoveryCensoringIndicator",
      Death_Censoring  = "DeathCensoringIndicator",
      Treatment        = "Treatment"
    )

    res_std <- do_cif_analysis(mydata_std, tau=15)
    res_std$RMLT1$groups

    ##            Group Estimate        se   Lower95  Upper95
    ## 1 Group1 (trt=1) 3.760347 0.4769287 2.8255670 4.695128
    ## 2 Group2 (trt=0) 1.167820 0.3530140 0.4759129 1.859728

    res_std$RMLT1$contrast

    ##     Contrast Estimate        se  Lower95  Upper95      p_value
    ## 1 Difference 2.592527 0.5933632 1.429535 3.755519 1.246981e-05

    res_std$RMLT2$groups

    ##            Group Estimate        se   Lower95  Upper95
    ## 1 Group1 (trt=1) 1.082678 0.3039021 0.4870301 1.678326
    ## 2 Group2 (trt=0) 2.743811 0.4912417 1.7809770 3.706644

    res_std$RMLT2$contrast

    ##     Contrast  Estimate       se   Lower95    Upper95     p_value
    ## 1 Difference -1.661133 0.577646 -2.793319 -0.5289465 0.004031413

    # Prepare weighted CIF data with updated variable names
    prepped_w <- prep_data_weighted_cif(
      data_main = raw,
      data_long = long,

      wID_main              = "ID",
      wTimeToRecovery_main  = "TimeToRecovery",
      wTimeToDeath_main     = "TimeToDeath",
      wRecov_Censoring_main = "RecoveryCensoringIndicator",
      wDeath_Censoring_main = "DeathCensoringIndicator",
      wTreatment_main       = "Treatment",
      wBaselineScore_main   = "BaselineScore",

      wID_long              = "PersonID",
      wADY_long             = "RelativeDay",
      wScore_long           = "OrdinalScore",

      wStates_death         = c(4,5,6,7),
      wWeights_death        = c(2,1.5,1,0.5),
      wStates_discharge     = c(4,5,6,7),
      wWeights_discharge    = c(0.5,1,1.5,2)
    )

    # Run Weighted CIF analysis at tau=15
    res_w15 <- do_weighted_cif_analysis(prepped_w, tau=15)
    res_w15$WRMLT1$groups

    ##            Group Estimate        se   Lower95  Upper95
    ## 1 Group1 (trt=1) 3.826796 0.6299957 2.5920047 5.061588
    ## 2 Group2 (trt=0) 1.152394 0.4870215 0.1978317 2.106956

    res_w15$WRMLT1$contrast

    ##     Contrast Estimate        se  Lower95  Upper95      p_value
    ## 1 Difference 2.674403 0.7962942 1.113666 4.235139 0.0007834951

    res_w15$WRMLT2$groups

    ##            Group Estimate        se   Lower95  Upper95
    ## 1 Group1 (trt=1) 1.732806 0.5549883 0.6450291 2.820583
    ## 2 Group2 (trt=0) 3.075604 0.6740444 1.7544772 4.396731

    res_w15$WRMLT2$contrast

    ##     Contrast  Estimate        se   Lower95   Upper95   p_value
    ## 1 Difference -1.342798 0.8731253 -3.054124 0.3685276 0.1240679

    # Run Weighted CIF analysis at tau=29
    res_w29 <- do_weighted_cif_analysis(prepped_w, tau=29)
    res_w29$WRMLT1$groups

    ##            Group  Estimate       se  Lower95   Upper95
    ## 1 Group1 (trt=1) 10.555337 1.393451 7.824174 13.286500
    ## 2 Group2 (trt=0)  3.759667 1.052295 1.697169  5.822164

    res_w29$WRMLT1$contrast

    ##     Contrast Estimate       se  Lower95  Upper95      p_value
    ## 1 Difference 6.795671 1.746147 3.373223 10.21812 9.949938e-05

    res_w29$WRMLT2$groups

    ##            Group Estimate       se  Lower95   Upper95
    ## 1 Group1 (trt=1) 5.091130 1.216564 2.706664  7.475595
    ## 2 Group2 (trt=0) 8.486232 1.469823 5.605378 11.367085

    res_w29$WRMLT2$contrast

    ##     Contrast  Estimate       se   Lower95   Upper95    p_value
    ## 1 Difference -3.395102 1.907986 -7.134753 0.3445499 0.07517143