Chapter 5 Competing Risks

The below code illustrates how to perform a Cox regression using a cause-specific hazard for competing risks models.

leaders$lost = factor(leaders$lost, 0:3, labels = c("In-Office", "Constitutional", "Natural", "Non-Constitutional"))
cox_nat <- coxph(Surv(years, lost == "Natural") ~ manner + start+military + age + conflict + loginc + growth + pop + land + literacy + factor(region), data = leaders)
summary(cox_nat)
## Call:
## coxph(formula = Surv(years, lost == "Natural") ~ manner + start + 
##     military + age + conflict + loginc + growth + pop + land + 
##     literacy + factor(region), data = leaders)
## 
##   n= 438, number of events= 27 
##    (34 observations deleted due to missingness)
## 
##                       coef  exp(coef)   se(coef)      z Pr(>|z|)    
## manner           3.747e-01  1.455e+00  6.633e-01  0.565    0.572    
## start           -5.403e-02  9.474e-01  3.386e-02 -1.596    0.111    
## military        -3.646e-01  6.945e-01  7.409e-01 -0.492    0.623    
## age              7.386e-02  1.077e+00  1.840e-02  4.015 5.95e-05 ***
## conflict        -2.609e-01  7.704e-01  4.720e-01 -0.553    0.580    
## loginc           3.285e-01  1.389e+00  2.673e-01  1.229    0.219    
## growth           8.817e-02  1.092e+00  8.518e-02  1.035    0.301    
## pop              1.991e-03  1.002e+00  2.138e-03  0.931    0.352    
## land            -3.969e-05  1.000e+00  1.781e-04 -0.223    0.824    
## literacy        -8.796e-03  9.912e-01  1.260e-02 -0.698    0.485    
## factor(region)1 -6.427e-01  5.259e-01  8.360e-01 -0.769    0.442    
## factor(region)2 -7.776e-01  4.595e-01  9.031e-01 -0.861    0.389    
## factor(region)3  6.591e-01  1.933e+00  7.852e-01  0.839    0.401    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                 exp(coef) exp(-coef) lower .95 upper .95
## manner             1.4546     0.6875   0.39644     5.337
## start              0.9474     1.0555   0.88657     1.012
## military           0.6945     1.4400   0.16255     2.967
## age                1.0767     0.9288   1.03853     1.116
## conflict           0.7704     1.2980   0.30548     1.943
## loginc             1.3889     0.7200   0.82251     2.345
## growth             1.0922     0.9156   0.92423     1.291
## pop                1.0020     0.9980   0.99780     1.006
## land               1.0000     1.0000   0.99961     1.000
## literacy           0.9912     1.0088   0.96707     1.016
## factor(region)1    0.5259     1.9015   0.10217     2.707
## factor(region)2    0.4595     2.1763   0.07827     2.698
## factor(region)3    1.9330     0.5173   0.41484     9.007
## 
## Concordance= 0.819  (se = 0.046 )
## Likelihood ratio test= 32.42  on 13 df,   p=0.002
## Wald test            = 29.47  on 13 df,   p=0.006
## Score (logrank) test = 33.21  on 13 df,   p=0.002

The following code illustrates how to do a competing risk model with Fine-Gray model.

# Cumulative Incidence Functions #
  cif.dat=leaders[leaders$lost!="In-Office",]  
  cif.tenure=cif.dat$years
  cif.status=cif.dat$lost

  cif.leaders=cuminc(cif.tenure,cif.status,rho=0)
  ggcompetingrisks(cif.leaders)

# Cox Regression Competing Risks #
 tenure=leaders$years
 View(leaders)
 status.leaders=leaders$lost
 x=leaders[,3:12]
 x$africa=ifelse(leaders$region==1,1,0)
 x$asia=ifelse(leaders$region==2,1,0)
 x$latin=ifelse(leaders$region==3,1,0)
 
 gray.natural=crr(tenure,status.leaders,x,failcode="Natural")
## 34 cases omitted due to missing values
 summary(gray.natural)
## Competing Risks Regression
## 
## Call:
## crr(ftime = tenure, fstatus = status.leaders, cov1 = x, failcode = "Natural")
## 
##               coef exp(coef) se(coef)        z p-value
## manner   -7.32e-02     0.929 0.562617 -0.13007  0.9000
## start    -8.33e-02     0.920 0.026453 -3.14757  0.0016
## military -2.51e-01     0.778 0.549101 -0.45674  0.6500
## age       4.75e-02     1.049 0.018127  2.62190  0.0087
## conflict -2.13e-03     0.998 0.440003 -0.00484  1.0000
## loginc    5.55e-01     1.741 0.261591  2.11995  0.0340
## growth    9.80e-02     1.103 0.128218  0.76408  0.4400
## pop       2.41e-03     1.002 0.002784  0.86500  0.3900
## land     -8.76e-05     1.000 0.000189 -0.46445  0.6400
## literacy -6.71e-03     0.993 0.011000 -0.60956  0.5400
## africa    4.44e-01     1.559 0.710063  0.62578  0.5300
## asia     -6.97e-01     0.498 0.821035 -0.84936  0.4000
## latin     1.22e-01     1.129 0.625890  0.19434  0.8500
## 
##          exp(coef) exp(-coef)   2.5% 97.5%
## manner       0.929      1.076 0.3085 2.800
## start        0.920      1.087 0.8736 0.969
## military     0.778      1.285 0.2653 2.283
## age          1.049      0.954 1.0121 1.087
## conflict     0.998      1.002 0.4213 2.364
## loginc       1.741      0.574 1.0427 2.907
## growth       1.103      0.907 0.8578 1.418
## pop          1.002      0.998 0.9970 1.008
## land         1.000      1.000 0.9995 1.000
## literacy     0.993      1.007 0.9721 1.015
## africa       1.559      0.641 0.3878 6.272
## asia         0.498      2.008 0.0996 2.489
## latin        1.129      0.885 0.3312 3.851
## 
## Num. cases = 438 (34 cases omitted due to missing values)
## Pseudo Log-likelihood = -149 
## Pseudo likelihood ratio test = 29.4  on 13 df,
 gray.const=crr(tenure,status.leaders,x,failcode="Constitutional")
## 34 cases omitted due to missing values
 summary(gray.const)
## Competing Risks Regression
## 
## Call:
## crr(ftime = tenure, fstatus = status.leaders, cov1 = x, failcode = "Constitutional")
## 
##               coef exp(coef) se(coef)        z p-value
## manner   -6.20e-01     0.538 2.64e-01 -2.34926  0.0190
## start    -1.79e-02     0.982 9.79e-03 -1.83105  0.0670
## military  1.22e-01     1.130 2.49e-01  0.48991  0.6200
## age       1.37e-02     1.014 8.45e-03  1.61657  0.1100
## conflict -1.67e-01     0.846 2.16e-01 -0.77554  0.4400
## loginc   -1.35e-01     0.874 1.15e-01 -1.17732  0.2400
## growth    4.18e-02     1.043 3.02e-02  1.38457  0.1700
## pop       6.68e-04     1.001 8.78e-04  0.76086  0.4500
## land     -2.74e-05     1.000 6.89e-05 -0.39672  0.6900
## literacy  1.88e-02     1.019 5.77e-03  3.25010  0.0012
## africa   -9.43e-01     0.389 3.94e-01 -2.39044  0.0170
## asia     -3.18e-03     0.997 3.69e-01 -0.00862  0.9900
## latin     8.25e-02     1.086 3.54e-01  0.23284  0.8200
## 
##          exp(coef) exp(-coef)  2.5% 97.5%
## manner       0.538      1.859 0.321 0.902
## start        0.982      1.018 0.964 1.001
## military     1.130      0.885 0.693 1.841
## age          1.014      0.986 0.997 1.031
## conflict     0.846      1.182 0.554 1.291
## loginc       0.874      1.145 0.697 1.094
## growth       1.043      0.959 0.983 1.106
## pop          1.001      0.999 0.999 1.002
## land         1.000      1.000 1.000 1.000
## literacy     1.019      0.981 1.007 1.031
## africa       0.389      2.568 0.180 0.844
## asia         0.997      1.003 0.484 2.053
## latin        1.086      0.921 0.542 2.174
## 
## Num. cases = 438 (34 cases omitted due to missing values)
## Pseudo Log-likelihood = -814 
## Pseudo likelihood ratio test = 101  on 13 df,
 gray.nonconst=crr(tenure,status.leaders,x,failcode="Non-Constitutional")
## 34 cases omitted due to missing values
 summary(gray.nonconst)
## Competing Risks Regression
## 
## Call:
## crr(ftime = tenure, fstatus = status.leaders, cov1 = x, failcode = "Non-Constitutional")
## 
##               coef exp(coef) se(coef)      z p-value
## manner    7.87e-01     2.196 0.196832  3.996 6.4e-05
## start    -5.61e-02     0.945 0.010553 -5.315 1.1e-07
## military -2.40e-01     0.787 0.200255 -1.199 2.3e-01
## age      -1.34e-03     0.999 0.008335 -0.161 8.7e-01
## conflict  5.35e-01     1.708 0.183801  2.912 3.6e-03
## loginc   -3.05e-01     0.737 0.128953 -2.363 1.8e-02
## growth   -5.26e-02     0.949 0.029720 -1.769 7.7e-02
## pop      -1.13e-03     0.999 0.000879 -1.284 2.0e-01
## land     -2.69e-05     1.000 0.000079 -0.341 7.3e-01
## literacy -9.43e-03     0.991 0.004066 -2.320 2.0e-02
## africa   -2.15e-01     0.807 0.284876 -0.753 4.5e-01
## asia     -4.99e-01     0.607 0.364670 -1.369 1.7e-01
## latin     3.67e-01     1.443 0.290395  1.263 2.1e-01
## 
##          exp(coef) exp(-coef)  2.5% 97.5%
## manner       2.196      0.455 1.493 3.230
## start        0.945      1.058 0.926 0.965
## military     0.787      1.271 0.531 1.165
## age          0.999      1.001 0.982 1.015
## conflict     1.708      0.586 1.191 2.448
## loginc       0.737      1.356 0.573 0.949
## growth       0.949      1.054 0.895 1.006
## pop          0.999      1.001 0.997 1.001
## land         1.000      1.000 1.000 1.000
## literacy     0.991      1.009 0.983 0.999
## africa       0.807      1.239 0.462 1.410
## asia         0.607      1.648 0.297 1.240
## latin        1.443      0.693 0.817 2.550
## 
## Num. cases = 438 (34 cases omitted due to missing values)
## Pseudo Log-likelihood = -855 
## Pseudo likelihood ratio test = 110  on 13 df,

5.1 Python code for competing risks models

In Python, you can easily use the cause-specific model (in either AFT or Cox PH models) by creating a new column with the event of interest being a “1” and censoring all other events (similar to what you did in Homework 2). However, Python is NOT able run a Fine-Gray model.