Search code examples
rsurvival-analysis

Using tidycmprsk (R) when no cases are censored


I am attempting to do a competing risks analysis using the package tidycmprsk in R.

My dataset is running into a problem because there are no censored cases (everyone in the dataset has experienced one of the three outcomes).

From the documentation:
The event status variable must be a factor, with the first level indicating ’censor’ and subsequent levels the competing risks.

Any ideas on how to get around this? Otherwise it's treating one of my levels/outcomes as censoring when it's actually an outcome of interest.

e.g. Below runs a cumulative incidence curve and gives results for two outcomes - death from cancer and death from other causes:

library(tidycmprsk)

cuminc(Surv(ttdeath, death_cr) ~ trt, trial)

But if you take out the censored cases, now it just gives results for one failure type thinking the other is your censored variable:

data <- trial %>%
  mutate(death_cr_new = case_when(
    death_cr=="censor" ~ 2,
    death_cr=="death from cancer" ~ 2,
    death_cr=="death other causes" ~ 3
  ))

data$death_cr_new<-as.factor(data$death_cr_new)

cuminc(Surv(ttdeath, death_cr_new) ~ trt, data)


Solution

  • Even if unobserved, the first level of the outcome factor must be the censoring level. Expanding your example, I added an unobserved level to the outcome to indicate censoring.

    library(tidycmprsk)
    
    data <- 
      trial %>%
      dplyr::mutate(
        death_cr_new = 
          dplyr::case_when(
            death_cr=="censor" ~ 2,
            death_cr=="death from cancer" ~ 2,
            death_cr=="death other causes" ~ 3
          ) %>%
          factor(levels = 1:3)
      )
    
    data$death_cr_new %>% table()
    #> .
    #>   1   2   3 
    #>   0 145  55
    
    
    cuminc(Surv(ttdeath, death_cr_new) ~ trt, data)
    #> 
    #> ── cuminc() ────────────────────────────────────────────────────────────────────
    #> • Failure type "2"
    #> strata   time   n.risk   estimate   std.error   95% CI          
    #> Drug A   5.00   97       0.000      0.000       NA, NA          
    #> Drug A   10.0   94       0.020      0.014       0.004, 0.065    
    #> Drug A   15.0   83       0.071      0.026       0.031, 0.134    
    #> Drug A   20.0   61       0.173      0.039       0.106, 0.255    
    #> Drug B   5.00   102      0.000      0.000       NA, NA          
    #> Drug B   10.0   95       0.039      0.019       0.013, 0.090    
    #> Drug B   15.0   75       0.167      0.037       0.102, 0.246    
    #> Drug B   20.0   55       0.255      0.043       0.175, 0.343
    #> • Failure type "3"
    #> strata   time   n.risk   estimate   std.error   95% CI          
    #> Drug A   5.00   97       0.010      0.010       0.001, 0.050    
    #> Drug A   10.0   94       0.020      0.014       0.004, 0.065    
    #> Drug A   15.0   83       0.082      0.028       0.038, 0.147    
    #> Drug A   20.0   61       0.204      0.041       0.131, 0.289    
    #> Drug B   5.00   102      0.000      0.000       NA, NA          
    #> Drug B   10.0   95       0.029      0.017       0.008, 0.077    
    #> Drug B   15.0   75       0.098      0.030       0.050, 0.165    
    #> Drug B   20.0   55       0.206      0.040       0.133, 0.289
    #> • Tests
    #> outcome   statistic   df     p.value    
    #> 2         1.03        1.00   0.31       
    #> 3         0.089       1.00   0.77
    

    Created on 2022-08-17 by the reprex package (v2.0.1)