Q1.

library(psfmi)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(survival)
mye <- read.csv("C:/Users/riema/Downloads/myeloma.csv")

str(mye)
## 'data.frame':    48 obs. of  10 variables:
##  $ patient: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ time   : int  13 52 6 40 10 7 66 10 10 14 ...
##  $ status : int  1 0 1 1 1 0 1 0 1 1 ...
##  $ age    : int  66 66 53 69 65 57 52 60 70 70 ...
##  $ sex    : int  1 1 2 1 1 2 1 1 1 1 ...
##  $ bun    : int  25 13 15 10 20 12 21 41 37 40 ...
##  $ ca     : int  10 11 13 10 10 8 10 9 12 11 ...
##  $ hb     : num  14.6 12 11.4 10.2 13.2 9.9 12.8 14 7.5 10.6 ...
##  $ pcells : int  18 100 33 30 66 45 11 70 47 27 ...
##  $ protein: int  1 0 1 1 0 0 1 1 0 0 ...
summary(mye)
##     patient           time           status          age             sex       
##  Min.   : 1.00   Min.   : 1.00   Min.   :0.00   Min.   :50.00   Min.   :1.000  
##  1st Qu.:12.75   1st Qu.: 6.75   1st Qu.:0.75   1st Qu.:58.75   1st Qu.:1.000  
##  Median :24.50   Median :14.50   Median :1.00   Median :62.50   Median :1.000  
##  Mean   :24.50   Mean   :23.38   Mean   :0.75   Mean   :62.90   Mean   :1.396  
##  3rd Qu.:36.25   3rd Qu.:37.00   3rd Qu.:1.00   3rd Qu.:68.25   3rd Qu.:2.000  
##  Max.   :48.00   Max.   :91.00   Max.   :1.00   Max.   :77.00   Max.   :2.000  
##       bun               ca               hb            pcells      
##  Min.   :  6.00   Min.   : 8.000   Min.   : 4.90   Min.   :  3.00  
##  1st Qu.: 13.75   1st Qu.: 9.000   1st Qu.: 8.65   1st Qu.: 21.25  
##  Median : 21.00   Median :10.000   Median :10.20   Median : 33.00  
##  Mean   : 33.92   Mean   : 9.938   Mean   :10.25   Mean   : 42.94  
##  3rd Qu.: 39.25   3rd Qu.:10.000   3rd Qu.:12.57   3rd Qu.: 63.00  
##  Max.   :172.00   Max.   :15.000   Max.   :14.60   Max.   :100.00  
##     protein      
##  Min.   :0.0000  
##  1st Qu.:0.0000  
##  Median :0.0000  
##  Mean   :0.3125  
##  3rd Qu.:1.0000  
##  Max.   :1.0000
# Make sure sex is treated as a factor
mye$sex <- factor(mye$sex, levels = c(1,2), labels = c("Male","Female"))


S <- Surv(time = mye$time, event = mye$status)

# Fit Cox Proportional Hazards model
cox_fit <- coxph(S ~ bun + ca + hb + pcells + protein + age + sex, data = mye)

# Display model summary
summary(cox_fit)
## Call:
## coxph(formula = S ~ bun + ca + hb + pcells + protein + age + 
##     sex, data = mye)
## 
##   n= 48, number of events= 36 
## 
##                coef exp(coef)  se(coef)      z Pr(>|z|)    
## bun        0.022661  1.022919  0.006110  3.709 0.000208 ***
## ca         0.013265  1.013353  0.132681  0.100 0.920363    
## hb        -0.133017  0.875450  0.068527 -1.941 0.052249 .  
## pcells    -0.001359  0.998642  0.006588 -0.206 0.836585    
## protein   -0.683269  0.504964  0.429395 -1.591 0.111556    
## age       -0.018056  0.982106  0.027833 -0.649 0.516521    
## sexFemale -0.249473  0.779211  0.403093 -0.619 0.535985    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##           exp(coef) exp(-coef) lower .95 upper .95
## bun          1.0229     0.9776    1.0107     1.035
## ca           1.0134     0.9868    0.7813     1.314
## hb           0.8755     1.1423    0.7654     1.001
## pcells       0.9986     1.0014    0.9858     1.012
## protein      0.5050     1.9803    0.2177     1.172
## age          0.9821     1.0182    0.9300     1.037
## sexFemale    0.7792     1.2833    0.3536     1.717
## 
## Concordance= 0.705  (se = 0.048 )
## Likelihood ratio test= 17.53  on 7 df,   p=0.01
## Wald test            = 20.01  on 7 df,   p=0.006
## Score (logrank) test = 25.59  on 7 df,   p=6e-04

##Q2.

pro <- read.csv("C:/Users/riema/Downloads/prostatic.csv")

str(pro)
## 'data.frame':    38 obs. of  8 variables:
##  $ patient  : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ treatment: int  1 2 2 1 2 1 1 1 2 1 ...
##  $ time     : int  65 61 60 58 51 51 14 43 16 52 ...
##  $ status   : int  0 0 0 0 0 0 1 0 0 0 ...
##  $ age      : int  67 60 77 64 65 61 73 60 73 73 ...
##  $ shb      : num  13.4 14.6 15.6 16.2 14.1 13.5 12.4 13.6 13.8 11.7 ...
##  $ size     : int  34 4 3 6 21 8 18 7 8 5 ...
##  $ index    : int  8 10 8 9 9 8 11 9 9 9 ...
summary(pro)
##     patient        treatment          time           status      
##  Min.   : 1.00   Min.   :1.000   Min.   : 2.00   Min.   :0.0000  
##  1st Qu.:10.25   1st Qu.:1.000   1st Qu.:42.25   1st Qu.:0.0000  
##  Median :19.50   Median :2.000   Median :56.00   Median :0.0000  
##  Mean   :19.50   Mean   :1.526   Mean   :49.74   Mean   :0.1579  
##  3rd Qu.:28.75   3rd Qu.:2.000   3rd Qu.:65.00   3rd Qu.:0.0000  
##  Max.   :38.00   Max.   :2.000   Max.   :70.00   Max.   :1.0000  
##       age             shb             size           index       
##  Min.   :51.00   Min.   :10.70   Min.   : 2.00   Min.   : 6.000  
##  1st Qu.:65.00   1st Qu.:13.43   1st Qu.: 4.00   1st Qu.: 8.000  
##  Median :71.00   Median :13.85   Median : 7.50   Median : 9.000  
##  Mean   :68.63   Mean   :13.94   Mean   :10.47   Mean   : 9.132  
##  3rd Qu.:73.00   3rd Qu.:14.68   3rd Qu.:13.75   3rd Qu.:10.000  
##  Max.   :77.00   Max.   :16.40   Max.   :37.00   Max.   :12.000
S <- Surv(time = pro$time, event = pro$status)


cox_age   <- coxph(S ~ age, data = pro)
cox_shb   <- coxph(S ~ shb, data = pro)
cox_size  <- coxph(S ~ size, data = pro)
cox_index <- coxph(S ~ index, data = pro)

summary(cox_age)
## Call:
## coxph(formula = S ~ age, data = pro)
## 
##   n= 38, number of events= 6 
## 
##         coef exp(coef) se(coef)      z Pr(>|z|)
## age -0.01683   0.98331  0.05879 -0.286    0.775
## 
##     exp(coef) exp(-coef) lower .95 upper .95
## age    0.9833      1.017    0.8763     1.103
## 
## Concordance= 0.46  (se = 0.123 )
## Likelihood ratio test= 0.08  on 1 df,   p=0.8
## Wald test            = 0.08  on 1 df,   p=0.8
## Score (logrank) test = 0.08  on 1 df,   p=0.8
summary(cox_shb)
## Call:
## coxph(formula = S ~ shb, data = pro)
## 
##   n= 38, number of events= 6 
## 
##       coef exp(coef) se(coef)     z Pr(>|z|)
## shb 0.1231    1.1310   0.3168 0.389    0.698
## 
##     exp(coef) exp(-coef) lower .95 upper .95
## shb     1.131     0.8841    0.6078     2.105
## 
## Concordance= 0.503  (se = 0.15 )
## Likelihood ratio test= 0.15  on 1 df,   p=0.7
## Wald test            = 0.15  on 1 df,   p=0.7
## Score (logrank) test = 0.15  on 1 df,   p=0.7
summary(cox_size)
## Call:
## coxph(formula = S ~ size, data = pro)
## 
##   n= 38, number of events= 6 
## 
##         coef exp(coef) se(coef)     z Pr(>|z|)   
## size 0.10143   1.10676  0.03739 2.713  0.00667 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##      exp(coef) exp(-coef) lower .95 upper .95
## size     1.107     0.9035     1.029     1.191
## 
## Concordance= 0.763  (se = 0.118 )
## Likelihood ratio test= 7.31  on 1 df,   p=0.007
## Wald test            = 7.36  on 1 df,   p=0.007
## Score (logrank) test = 9.64  on 1 df,   p=0.002
summary(cox_index)
## Call:
## coxph(formula = S ~ index, data = pro)
## 
##   n= 38, number of events= 6 
## 
##         coef exp(coef) se(coef)     z Pr(>|z|)  
## index 0.8794    2.4094   0.3473 2.532   0.0113 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##       exp(coef) exp(-coef) lower .95 upper .95
## index     2.409      0.415      1.22     4.759
## 
## Concordance= 0.84  (se = 0.072 )
## Likelihood ratio test= 7.22  on 1 df,   p=0.007
## Wald test            = 6.41  on 1 df,   p=0.01
## Score (logrank) test = 7.26  on 1 df,   p=0.007

So tumor size and Gleason index have p-values less than 0.05, therefore they are significantly associated with survival time.

pro$treatment <- factor(pro$treatment, levels = c(1,2), labels = c("Placebo","DES"))


cox_adj <- coxph(S ~ treatment + size + index, data = pro)

summary(cox_adj)
## Call:
## coxph(formula = S ~ treatment + size + index, data = pro)
## 
##   n= 38, number of events= 6 
## 
##                  coef exp(coef) se(coef)      z Pr(>|z|)  
## treatmentDES -1.11272   0.32866  1.20313 -0.925   0.3550  
## size          0.08257   1.08608  0.04746  1.740   0.0819 .
## index         0.71025   2.03450  0.33791  2.102   0.0356 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##              exp(coef) exp(-coef) lower .95 upper .95
## treatmentDES    0.3287     3.0426   0.03109     3.474
## size            1.0861     0.9207   0.98961     1.192
## index           2.0345     0.4915   1.04913     3.945
## 
## Concordance= 0.873  (se = 0.071 )
## Likelihood ratio test= 13.78  on 3 df,   p=0.003
## Wald test            = 10.29  on 3 df,   p=0.02
## Score (logrank) test = 14.9  on 3 df,   p=0.002

Q3.

lung <- read.csv("C:/Users/riema/Downloads/lung.csv")
str(lung) 
## 'data.frame':    196 obs. of  7 variables:
##  $ patient: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ time   : int  2324 108 2939 1258 2904 444 158 1686 142 1624 ...
##  $ status : int  1 1 0 0 0 1 1 1 1 1 ...
##  $ age    : int  59 28 55 62 51 59 55 53 47 53 ...
##  $ gender : int  1 1 1 1 1 1 2 2 1 2 ...
##  $ bmi    : num  29.6 22.6 32.1 30 30.4 26.9 24.6 26.8 32.2 15.7 ...
##  $ disease: int  1 3 2 2 2 2 1 1 2 1 ...
summary(lung)
##     patient            time            status            age       
##  Min.   :  1.00   Min.   :   3.0   Min.   :0.0000   Min.   :18.00  
##  1st Qu.: 49.75   1st Qu.: 182.2   1st Qu.:0.0000   1st Qu.:41.75  
##  Median : 98.50   Median : 843.5   Median :1.0000   Median :53.00  
##  Mean   : 98.50   Mean   :1182.2   Mean   :0.6276   Mean   :48.56  
##  3rd Qu.:147.25   3rd Qu.:2387.5   3rd Qu.:1.0000   3rd Qu.:58.00  
##  Max.   :196.00   Max.   :2939.0   Max.   :1.0000   Max.   :67.00  
##      gender           bmi           disease     
##  Min.   :1.000   Min.   :14.00   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:19.50   1st Qu.:1.000  
##  Median :1.000   Median :22.60   Median :2.000  
##  Mean   :1.429   Mean   :23.42   Mean   :2.168  
##  3rd Qu.:2.000   3rd Qu.:27.52   3rd Qu.:3.000  
##  Max.   :2.000   Max.   :35.20   Max.   :4.000
S <- Surv(time = lung$time, event = lung$status)
km_fit <- survfit(S ~ 1, data = lung)
summary(km_fit)
## Call: survfit(formula = S ~ 1, data = lung)
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##     3    196       1    0.995 0.00509        0.985        1.000
##     4    195       1    0.990 0.00718        0.976        1.000
##    16    193       1    0.985 0.00878        0.968        1.000
##    21    192       1    0.980 0.01013        0.960        1.000
##    22    191       1    0.974 0.01130        0.953        0.997
##    25    190       1    0.969 0.01235        0.945        0.994
##    29    189       1    0.964 0.01330        0.938        0.991
##    31    188       2    0.954 0.01501        0.925        0.984
##    38    186       2    0.944 0.01651        0.912        0.977
##    55    184       1    0.939 0.01720        0.905        0.973
##    61    183       1    0.933 0.01785        0.899        0.969
##    63    182       1    0.928 0.01847        0.893        0.965
##    65    181       1    0.923 0.01907        0.886        0.961
##    70    180       1    0.918 0.01964        0.880        0.957
##    73    179       1    0.913 0.02019        0.874        0.953
##    76    178       1    0.908 0.02072        0.868        0.949
##    80    177       1    0.903 0.02123        0.862        0.945
##    85    176       1    0.897 0.02172        0.856        0.941
##    88    175       1    0.892 0.02219        0.850        0.937
##    92    174       1    0.887 0.02265        0.844        0.933
##    95    173       1    0.882 0.02309        0.838        0.929
##   104    172       1    0.877 0.02352        0.832        0.924
##   108    171       1    0.872 0.02393        0.826        0.920
##   114    170       1    0.867 0.02434        0.820        0.916
##   121    169       2    0.856 0.02511        0.809        0.907
##   123    167       1    0.851 0.02547        0.803        0.903
##   124    166       1    0.846 0.02583        0.797        0.898
##   128    165       1    0.841 0.02618        0.791        0.894
##   132    164       1    0.836 0.02652        0.786        0.890
##   134    163       1    0.831 0.02685        0.780        0.885
##   136    162       1    0.826 0.02717        0.774        0.881
##   142    161       1    0.821 0.02748        0.768        0.876
##   148    160       1    0.815 0.02778        0.763        0.872
##   151    159       1    0.810 0.02807        0.757        0.867
##   153    158       1    0.805 0.02836        0.751        0.863
##   158    157       3    0.790 0.02918        0.735        0.849
##   159    154       1    0.785 0.02943        0.729        0.845
##   162    153       1    0.780 0.02969        0.723        0.840
##   165    152       1    0.774 0.02993        0.718        0.835
##   169    151       1    0.769 0.03017        0.712        0.831
##   174    150       1    0.764 0.03040        0.707        0.826
##   175    149       1    0.759 0.03063        0.701        0.821
##   177    148       1    0.754 0.03084        0.696        0.817
##   184    147       1    0.749 0.03106        0.690        0.812
##   192    146       2    0.739 0.03147        0.679        0.803
##   199    144       1    0.733 0.03166        0.674        0.798
##   203    143       1    0.728 0.03186        0.668        0.793
##   209    142       1    0.723 0.03204        0.663        0.789
##   231    141       1    0.718 0.03222        0.658        0.784
##   237    140       1    0.713 0.03240        0.652        0.779
##   239    139       1    0.708 0.03257        0.647        0.775
##   257    138       1    0.703 0.03273        0.641        0.770
##   273    136       1    0.697 0.03290        0.636        0.765
##   278    135       1    0.692 0.03306        0.630        0.760
##   288    134       1    0.687 0.03321        0.625        0.755
##   290    133       1    0.682 0.03336        0.620        0.751
##   294    132       1    0.677 0.03351        0.614        0.746
##   310    131       1    0.672 0.03365        0.609        0.741
##   311    130       1    0.666 0.03378        0.603        0.736
##   313    129       1    0.661 0.03391        0.598        0.731
##   320    128       1    0.656 0.03404        0.593        0.726
##   335    125       1    0.651 0.03417        0.587        0.721
##   343    124       1    0.646 0.03429        0.582        0.716
##   354    123       1    0.640 0.03441        0.576        0.711
##   371    121       1    0.635 0.03453        0.571        0.706
##   410    120       1    0.630 0.03465        0.565        0.701
##   431    118       1    0.624 0.03477        0.560        0.696
##   437    117       1    0.619 0.03488        0.554        0.691
##   444    116       1    0.614 0.03498        0.549        0.686
##   461    115       1    0.608 0.03508        0.543        0.681
##   535    113       1    0.603 0.03518        0.538        0.676
##   549    112       1    0.598 0.03528        0.532        0.671
##   563    111       1    0.592 0.03537        0.527        0.666
##   625    109       1    0.587 0.03546        0.521        0.661
##   642    108       1    0.581 0.03554        0.516        0.655
##   683    106       1    0.576 0.03563        0.510        0.650
##   689    105       1    0.570 0.03571        0.505        0.645
##   697    104       1    0.565 0.03578        0.499        0.640
##   711    103       2    0.554 0.03592        0.488        0.629
##   744    101       1    0.548 0.03598        0.482        0.624
##   749    100       1    0.543 0.03604        0.477        0.618
##   797     99       1    0.538 0.03609        0.471        0.613
##   890     98       1    0.532 0.03613        0.466        0.608
##   962     96       1    0.526 0.03618        0.460        0.602
##   967     95       1    0.521 0.03622        0.455        0.597
##   969     94       1    0.515 0.03626        0.449        0.592
##  1032     92       1    0.510 0.03629        0.443        0.586
##  1104     89       1    0.504 0.03634        0.438        0.581
##  1125     87       1    0.498 0.03638        0.432        0.575
##  1173     85       1    0.492 0.03642        0.426        0.569
##  1208     84       1    0.487 0.03645        0.420        0.564
##  1290     81       1    0.481 0.03650        0.414        0.558
##  1321     80       1    0.475 0.03653        0.408        0.552
##  1405     76       1    0.468 0.03658        0.402        0.546
##  1419     75       1    0.462 0.03662        0.396        0.540
##  1474     74       1    0.456 0.03665        0.389        0.534
##  1477     73       1    0.450 0.03668        0.383        0.528
##  1553     71       1    0.443 0.03671        0.377        0.521
##  1624     69       1    0.437 0.03673        0.370        0.515
##  1686     68       1    0.430 0.03675        0.364        0.509
##  1836     67       1    0.424 0.03676        0.358        0.502
##  1901     66       1    0.418 0.03676        0.351        0.496
##  1987     65       1    0.411 0.03675        0.345        0.490
##  1991     64       1    0.405 0.03673        0.339        0.483
##  2071     62       1    0.398 0.03672        0.332        0.477
##  2162     60       1    0.392 0.03670        0.326        0.470
##  2212     59       1    0.385 0.03667        0.319        0.464
##  2230     58       1    0.378 0.03663        0.313        0.457
##  2303     56       1    0.372 0.03660        0.306        0.451
##  2317     55       1    0.365 0.03655        0.300        0.444
##  2324     54       1    0.358 0.03649        0.293        0.437
##  2349     53       1    0.351 0.03642        0.287        0.430
##  2375     51       1    0.344 0.03635        0.280        0.424
##  2378     50       1    0.337 0.03627        0.273        0.417
##  2479     44       1    0.330 0.03625        0.266        0.409
##  2550     35       1    0.320 0.03642        0.256        0.400
cage   <- coxph(S ~ age, data = lung)
cgen <- coxph(S ~ gender, data = lung)
cbmi   <- coxph(S ~ bmi, data = lung)

summary(cage)
## Call:
## coxph(formula = S ~ age, data = lung)
## 
##   n= 196, number of events= 123 
## 
##         coef exp(coef) se(coef)     z Pr(>|z|)
## age 0.002686  1.002690 0.007549 0.356    0.722
## 
##     exp(coef) exp(-coef) lower .95 upper .95
## age     1.003     0.9973     0.988     1.018
## 
## Concordance= 0.535  (se = 0.028 )
## Likelihood ratio test= 0.13  on 1 df,   p=0.7
## Wald test            = 0.13  on 1 df,   p=0.7
## Score (logrank) test = 0.13  on 1 df,   p=0.7
summary(cgen)
## Call:
## coxph(formula = S ~ gender, data = lung)
## 
##   n= 196, number of events= 123 
## 
##           coef exp(coef) se(coef)      z Pr(>|z|)
## gender -0.1532    0.8580   0.1840 -0.833    0.405
## 
##        exp(coef) exp(-coef) lower .95 upper .95
## gender     0.858      1.166    0.5982     1.231
## 
## Concordance= 0.53  (se = 0.023 )
## Likelihood ratio test= 0.7  on 1 df,   p=0.4
## Wald test            = 0.69  on 1 df,   p=0.4
## Score (logrank) test = 0.69  on 1 df,   p=0.4
summary(cbmi)
## Call:
## coxph(formula = S ~ bmi, data = lung)
## 
##   n= 196, number of events= 123 
## 
##        coef exp(coef) se(coef)     z Pr(>|z|)
## bmi 0.02111   1.02134  0.01916 1.102    0.271
## 
##     exp(coef) exp(-coef) lower .95 upper .95
## bmi     1.021     0.9791    0.9837      1.06
## 
## Concordance= 0.539  (se = 0.027 )
## Likelihood ratio test= 1.2  on 1 df,   p=0.3
## Wald test            = 1.21  on 1 df,   p=0.3
## Score (logrank) test = 1.22  on 1 df,   p=0.3
cox_adj <- coxph(S ~ age + gender + bmi, data = lung)
summary(cox_adj)
## Call:
## coxph(formula = S ~ age + gender + bmi, data = lung)
## 
##   n= 196, number of events= 123 
## 
##              coef  exp(coef)   se(coef)      z Pr(>|z|)
## age    -0.0002291  0.9997709  0.0080964 -0.028    0.977
## gender -0.1088577  0.8968580  0.1905332 -0.571    0.568
## bmi     0.0183592  1.0185287  0.0209644  0.876    0.381
## 
##        exp(coef) exp(-coef) lower .95 upper .95
## age       0.9998     1.0002    0.9840     1.016
## gender    0.8969     1.1150    0.6174     1.303
## bmi       1.0185     0.9818    0.9775     1.061
## 
## Concordance= 0.551  (se = 0.027 )
## Likelihood ratio test= 1.53  on 3 df,   p=0.7
## Wald test            = 1.54  on 3 df,   p=0.7
## Score (logrank) test = 1.54  on 3 df,   p=0.7
ph_test <- cox.zph(cox_adj)
print(ph_test)
##        chisq df    p
## age    0.105  1 0.75
## gender 1.893  1 0.17
## bmi    1.493  1 0.22
## GLOBAL 2.718  3 0.44
plot(ph_test)

ph_test$table
##            chisq df         p
## age    0.1047716  1 0.7461769
## gender 1.8928713  1 0.1688784
## bmi    1.4931801  1 0.2217237
## GLOBAL 2.7183117  3 0.4371244

None have a p-value of less than 0.05, so none of them appear to be time dependent

Q4.

library(dplyr)
library(survival)
jasa <- read.csv("C:/Users/riema/Downloads/jasa.csv")


jasa2 <- subset(jasa, futime > 0)
jasa2$id<-seq_len(nrow(jasa2))


td <- tmerge(
  data1 = jasa2,
  data2 = jasa2,
  id =id,
  death = event(futime, fustat),
  transplant0 = tdc(wait.time)
  
)
names(td)
##  [1] "birth.dt"    "accept.dt"   "tx.date"     "fu.date"     "fustat"     
##  [6] "surgery"     "age"         "futime"      "wait.time"   "transplant" 
## [11] "mismatch"    "hla.a2"      "mscore"      "reject"      "id"         
## [16] "tstart"      "tstop"       "death"       "transplant0"
cox_td <- coxph(
  Surv(tstart, tstop, death) ~ transplant0 + age + mscore,
  data = td
)
summary(cox_td)
## Call:
## coxph(formula = Surv(tstart, tstop, death) ~ transplant0 + age + 
##     mscore, data = td)
## 
##   n= 127, number of events= 41 
##    (41 observations deleted due to missingness)
## 
##                 coef exp(coef) se(coef)     z Pr(>|z|)  
## transplant0  2.75015  15.64499  1.10408 2.491   0.0127 *
## age          0.05674   1.05838  0.02313 2.453   0.0142 *
## mscore       0.46274   1.58842  0.28345 1.633   0.1026  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##             exp(coef) exp(-coef) lower .95 upper .95
## transplant0    15.645    0.06392    1.7971   136.199
## age             1.058    0.94484    1.0115     1.107
## mscore          1.588    0.62956    0.9114     2.768
## 
## Concordance= 0.708  (se = 0.045 )
## Likelihood ratio test= 22.14  on 3 df,   p=6e-05
## Wald test            = 14.99  on 3 df,   p=0.002
## Score (logrank) test = 17.46  on 3 df,   p=6e-04
test <- cox.zph(cox_td)
test
##             chisq df    p
## transplant0 0.449  1 0.50
## age         1.881  1 0.17
## mscore      0.917  1 0.34
## GLOBAL      3.396  3 0.33

None of the p-values are less than 0.05, therefore we can determine that the proportional hazards assumption for this model holds.

Treating the transplant as a time-dependent covariate allows the model to produce an estimate of the effect of the transplant by comparing mortality risk of patients who are waiting and patients who have recieved a transplant.

The hazards ratio given from our transplant0 covariate indicate that a patient’s risk of death is approximately 94% lower than before transplant.