title: “Assignment three” author: “ALETHEA” date: “2025-03-01” output: html_document

library(survival)
library(survminer)
## Loading required package: ggplot2
## Loading required package: ggpubr
## 
## Attaching package: 'survminer'
## The following object is masked from 'package:survival':
## 
##     myeloma
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
data<-veteran
head(data)
##   trt celltype time status karno diagtime age prior
## 1   1 squamous   72      1    60        7  69     0
## 2   1 squamous  411      1    70        5  64    10
## 3   1 squamous  228      1    60        3  38     0
## 4   1 squamous  126      1    60        9  63    10
## 5   1 squamous  118      1    70       11  65    10
## 6   1 squamous   10      1    20        5  49     0
summary(veteran)
##       trt             celltype       time           status      
##  Min.   :1.000   squamous :35   Min.   :  1.0   Min.   :0.0000  
##  1st Qu.:1.000   smallcell:48   1st Qu.: 25.0   1st Qu.:1.0000  
##  Median :1.000   adeno    :27   Median : 80.0   Median :1.0000  
##  Mean   :1.496   large    :27   Mean   :121.6   Mean   :0.9343  
##  3rd Qu.:2.000                  3rd Qu.:144.0   3rd Qu.:1.0000  
##  Max.   :2.000                  Max.   :999.0   Max.   :1.0000  
##      karno          diagtime           age            prior      
##  Min.   :10.00   Min.   : 1.000   Min.   :34.00   Min.   : 0.00  
##  1st Qu.:40.00   1st Qu.: 3.000   1st Qu.:51.00   1st Qu.: 0.00  
##  Median :60.00   Median : 5.000   Median :62.00   Median : 0.00  
##  Mean   :58.57   Mean   : 8.774   Mean   :58.31   Mean   : 2.92  
##  3rd Qu.:75.00   3rd Qu.:11.000   3rd Qu.:66.00   3rd Qu.:10.00  
##  Max.   :99.00   Max.   :87.000   Max.   :81.00   Max.   :10.00
veteran$trt <- factor(veteran$trt, 
                     levels = c(1, 2),
                     labels = c("Standard", "Test"))
veteran$prior <- factor(veteran$prior, 
                       levels = c(0, 10),
                       labels = c("No", "Yes"))
veteran$celltype <- factor(veteran$celltype)              
surv_obj <- Surv(time = veteran$time, event = veteran$status)

1. KAPLAN-MEIER SURVIVAL ANALYSIS

km_fit <- survfit(surv_obj ~ 1, data = veteran)
summary(km_fit)
## Call: survfit(formula = surv_obj ~ 1, data = veteran)
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##     1    137       2    0.985 0.01025      0.96552       1.0000
##     2    135       1    0.978 0.01250      0.95390       1.0000
##     3    134       1    0.971 0.01438      0.94302       0.9994
##     4    133       1    0.964 0.01602      0.93261       0.9954
##     7    132       3    0.942 0.02003      0.90315       0.9817
##     8    129       4    0.912 0.02415      0.86628       0.9610
##    10    125       2    0.898 0.02588      0.84850       0.9500
##    11    123       1    0.891 0.02668      0.83973       0.9444
##    12    122       2    0.876 0.02817      0.82241       0.9329
##    13    120       2    0.861 0.02953      0.80534       0.9212
##    15    118       2    0.847 0.03078      0.78849       0.9092
##    16    116       1    0.839 0.03137      0.78013       0.9032
##    18    115       3    0.818 0.03300      0.75533       0.8848
##    19    112       2    0.803 0.03399      0.73900       0.8724
##    20    110       2    0.788 0.03490      0.72280       0.8598
##    21    108       2    0.774 0.03575      0.70674       0.8471
##    22    106       1    0.766 0.03615      0.69875       0.8407
##    24    105       2    0.752 0.03690      0.68286       0.8277
##    25    103       3    0.730 0.03793      0.65924       0.8082
##    27     99       1    0.723 0.03826      0.65133       0.8016
##    29     98       1    0.715 0.03857      0.64344       0.7949
##    30     97       2    0.700 0.03916      0.62774       0.7816
##    31     95       2    0.686 0.03970      0.61213       0.7681
##    33     93       1    0.678 0.03995      0.60436       0.7613
##    35     92       1    0.671 0.04019      0.59661       0.7545
##    36     91       1    0.664 0.04042      0.58889       0.7477
##    42     90       1    0.656 0.04064      0.58119       0.7409
##    43     89       1    0.649 0.04085      0.57351       0.7340
##    44     88       1    0.641 0.04104      0.56585       0.7272
##    45     87       1    0.634 0.04123      0.55821       0.7203
##    48     86       1    0.627 0.04140      0.55059       0.7133
##    49     85       1    0.619 0.04157      0.54299       0.7064
##    51     84       3    0.597 0.04200      0.52032       0.6855
##    52     81       3    0.575 0.04234      0.49782       0.6644
##    53     78       1    0.568 0.04243      0.49036       0.6573
##    54     77       2    0.553 0.04259      0.47549       0.6431
##    56     75       1    0.546 0.04266      0.46808       0.6360
##    59     74       1    0.538 0.04272      0.46070       0.6288
##    61     73       1    0.531 0.04276      0.45333       0.6216
##    63     72       1    0.523 0.04280      0.44598       0.6145
##    72     71       1    0.516 0.04283      0.43864       0.6073
##    73     70       1    0.509 0.04284      0.43133       0.6000
##    80     69       2    0.494 0.04285      0.41675       0.5855
##    82     67       1    0.487 0.04284      0.40949       0.5783
##    84     65       1    0.479 0.04283      0.40212       0.5709
##    87     64       1    0.472 0.04281      0.39478       0.5635
##    90     62       1    0.464 0.04279      0.38731       0.5560
##    92     61       1    0.456 0.04276      0.37986       0.5484
##    95     60       2    0.441 0.04267      0.36504       0.5333
##    99     57       2    0.426 0.04255      0.35000       0.5179
##   100     55       1    0.418 0.04248      0.34251       0.5101
##   103     53       1    0.410 0.04240      0.33488       0.5022
##   105     51       1    0.402 0.04233      0.32711       0.4942
##   110     50       1    0.394 0.04224      0.31936       0.4861
##   111     49       2    0.378 0.04201      0.30395       0.4700
##   112     47       1    0.370 0.04188      0.29628       0.4618
##   117     46       2    0.354 0.04158      0.28103       0.4455
##   118     44       1    0.346 0.04140      0.27345       0.4372
##   122     43       1    0.338 0.04121      0.26589       0.4290
##   126     41       1    0.329 0.04102      0.25815       0.4206
##   132     40       1    0.321 0.04082      0.25044       0.4121
##   133     39       1    0.313 0.04059      0.24277       0.4036
##   139     38       1    0.305 0.04035      0.23513       0.3951
##   140     37       1    0.297 0.04009      0.22752       0.3865
##   143     36       1    0.288 0.03982      0.21994       0.3779
##   144     35       1    0.280 0.03952      0.21240       0.3693
##   151     34       1    0.272 0.03921      0.20490       0.3606
##   153     33       1    0.264 0.03888      0.19743       0.3519
##   156     32       1    0.255 0.03852      0.18999       0.3432
##   162     31       2    0.239 0.03776      0.17525       0.3256
##   164     29       1    0.231 0.03734      0.16793       0.3168
##   177     28       1    0.222 0.03691      0.16066       0.3079
##   186     26       1    0.214 0.03647      0.15310       0.2987
##   200     25       1    0.205 0.03600      0.14560       0.2895
##   201     24       1    0.197 0.03550      0.13814       0.2802
##   216     23       1    0.188 0.03497      0.13075       0.2709
##   228     22       1    0.180 0.03441      0.12341       0.2615
##   231     21       1    0.171 0.03382      0.11613       0.2520
##   242     19       1    0.162 0.03322      0.10846       0.2422
##   250     18       1    0.153 0.03257      0.10088       0.2323
##   260     17       1    0.144 0.03187      0.09338       0.2223
##   278     16       1    0.135 0.03113      0.08598       0.2122
##   283     15       1    0.126 0.03033      0.07867       0.2020
##   287     14       1    0.117 0.02947      0.07147       0.1917
##   314     13       1    0.108 0.02854      0.06439       0.1813
##   340     12       1    0.099 0.02755      0.05743       0.1708
##   357     11       1    0.090 0.02647      0.05061       0.1602
##   378     10       1    0.081 0.02531      0.04394       0.1495
##   384      9       1    0.072 0.02405      0.03744       0.1386
##   389      8       1    0.063 0.02267      0.03115       0.1275
##   392      7       1    0.054 0.02114      0.02509       0.1163
##   411      6       1    0.045 0.01944      0.01931       0.1049
##   467      5       1    0.036 0.01751      0.01389       0.0934
##   553      4       1    0.027 0.01528      0.00892       0.0818
##   587      3       1    0.018 0.01256      0.00459       0.0707
##   991      2       1    0.009 0.00894      0.00129       0.0631
##   999      1       1    0.000     NaN           NA           NA
ggsurvplot(km_fit,
           data = veteran,
           conf.int = TRUE,
           risk.table = TRUE,
           surv.median.line = "hv",
           title = "Kaplan-Meier Survival Curve - All Patients",
           xlab = "Time (days)",
           ylab = "Survival Probability")

km_trt <- survfit(surv_obj ~ trt, data = veteran)
summary(km_trt)
## Call: survfit(formula = surv_obj ~ trt, data = veteran)
## 
##                 trt=Standard 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##     3     69       1   0.9855  0.0144      0.95771        1.000
##     4     68       1   0.9710  0.0202      0.93223        1.000
##     7     67       1   0.9565  0.0246      0.90959        1.000
##     8     66       2   0.9275  0.0312      0.86834        0.991
##    10     64       2   0.8986  0.0363      0.83006        0.973
##    11     62       1   0.8841  0.0385      0.81165        0.963
##    12     61       2   0.8551  0.0424      0.77592        0.942
##    13     59       1   0.8406  0.0441      0.75849        0.932
##    16     58       1   0.8261  0.0456      0.74132        0.921
##    18     57       2   0.7971  0.0484      0.70764        0.898
##    20     55       1   0.7826  0.0497      0.69109        0.886
##    21     54       1   0.7681  0.0508      0.67472        0.874
##    22     53       1   0.7536  0.0519      0.65851        0.862
##    27     51       1   0.7388  0.0529      0.64208        0.850
##    30     50       1   0.7241  0.0539      0.62580        0.838
##    31     49       1   0.7093  0.0548      0.60967        0.825
##    35     48       1   0.6945  0.0556      0.59368        0.812
##    42     47       1   0.6797  0.0563      0.57782        0.800
##    51     46       1   0.6650  0.0570      0.56209        0.787
##    52     45       1   0.6502  0.0576      0.54649        0.774
##    54     44       2   0.6206  0.0587      0.51565        0.747
##    56     42       1   0.6059  0.0591      0.50040        0.734
##    59     41       1   0.5911  0.0595      0.48526        0.720
##    63     40       1   0.5763  0.0598      0.47023        0.706
##    72     39       1   0.5615  0.0601      0.45530        0.693
##    82     38       1   0.5467  0.0603      0.44049        0.679
##    92     37       1   0.5320  0.0604      0.42577        0.665
##    95     36       1   0.5172  0.0605      0.41116        0.651
##   100     34       1   0.5020  0.0606      0.39615        0.636
##   103     32       1   0.4863  0.0607      0.38070        0.621
##   105     31       1   0.4706  0.0608      0.36537        0.606
##   110     30       1   0.4549  0.0607      0.35018        0.591
##   117     29       2   0.4235  0.0605      0.32017        0.560
##   118     27       1   0.4079  0.0602      0.30537        0.545
##   122     26       1   0.3922  0.0599      0.29069        0.529
##   126     24       1   0.3758  0.0596      0.27542        0.513
##   132     23       1   0.3595  0.0592      0.26031        0.496
##   139     22       1   0.3432  0.0587      0.24535        0.480
##   143     21       1   0.3268  0.0582      0.23057        0.463
##   144     20       1   0.3105  0.0575      0.21595        0.446
##   151     19       1   0.2941  0.0568      0.20151        0.429
##   153     18       1   0.2778  0.0559      0.18725        0.412
##   156     17       1   0.2614  0.0550      0.17317        0.395
##   162     16       2   0.2288  0.0527      0.14563        0.359
##   177     14       1   0.2124  0.0514      0.13218        0.341
##   200     12       1   0.1947  0.0501      0.11761        0.322
##   216     11       1   0.1770  0.0486      0.10340        0.303
##   228     10       1   0.1593  0.0468      0.08956        0.283
##   250      9       1   0.1416  0.0448      0.07614        0.263
##   260      8       1   0.1239  0.0426      0.06318        0.243
##   278      7       1   0.1062  0.0400      0.05076        0.222
##   287      6       1   0.0885  0.0371      0.03896        0.201
##   314      5       1   0.0708  0.0336      0.02793        0.180
##   384      4       1   0.0531  0.0295      0.01788        0.158
##   392      3       1   0.0354  0.0244      0.00917        0.137
##   411      2       1   0.0177  0.0175      0.00256        0.123
##   553      1       1   0.0000     NaN           NA           NA
## 
##                 trt=Test 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##     1     68       2   0.9706  0.0205      0.93125        1.000
##     2     66       1   0.9559  0.0249      0.90830        1.000
##     7     65       2   0.9265  0.0317      0.86647        0.991
##     8     63       2   0.8971  0.0369      0.82766        0.972
##    13     61       1   0.8824  0.0391      0.80900        0.962
##    15     60       2   0.8529  0.0429      0.77278        0.941
##    18     58       1   0.8382  0.0447      0.75513        0.930
##    19     57       2   0.8088  0.0477      0.72056        0.908
##    20     55       1   0.7941  0.0490      0.70360        0.896
##    21     54       1   0.7794  0.0503      0.68684        0.884
##    24     53       2   0.7500  0.0525      0.65383        0.860
##    25     51       3   0.7059  0.0553      0.60548        0.823
##    29     48       1   0.6912  0.0560      0.58964        0.810
##    30     47       1   0.6765  0.0567      0.57394        0.797
##    31     46       1   0.6618  0.0574      0.55835        0.784
##    33     45       1   0.6471  0.0580      0.54289        0.771
##    36     44       1   0.6324  0.0585      0.52754        0.758
##    43     43       1   0.6176  0.0589      0.51230        0.745
##    44     42       1   0.6029  0.0593      0.49717        0.731
##    45     41       1   0.5882  0.0597      0.48216        0.718
##    48     40       1   0.5735  0.0600      0.46724        0.704
##    49     39       1   0.5588  0.0602      0.45244        0.690
##    51     38       2   0.5294  0.0605      0.42313        0.662
##    52     36       2   0.5000  0.0606      0.39423        0.634
##    53     34       1   0.4853  0.0606      0.37993        0.620
##    61     33       1   0.4706  0.0605      0.36573        0.606
##    73     32       1   0.4559  0.0604      0.35163        0.591
##    80     31       2   0.4265  0.0600      0.32373        0.562
##    84     28       1   0.4112  0.0597      0.30935        0.547
##    87     27       1   0.3960  0.0594      0.29509        0.531
##    90     25       1   0.3802  0.0591      0.28028        0.516
##    95     24       1   0.3643  0.0587      0.26560        0.500
##    99     23       2   0.3326  0.0578      0.23670        0.467
##   111     20       2   0.2994  0.0566      0.20673        0.434
##   112     18       1   0.2827  0.0558      0.19203        0.416
##   133     17       1   0.2661  0.0550      0.17754        0.399
##   140     16       1   0.2495  0.0540      0.16326        0.381
##   164     15       1   0.2329  0.0529      0.14920        0.363
##   186     14       1   0.2162  0.0517      0.13538        0.345
##   201     13       1   0.1996  0.0503      0.12181        0.327
##   231     12       1   0.1830  0.0488      0.10851        0.308
##   242     10       1   0.1647  0.0472      0.09389        0.289
##   283      9       1   0.1464  0.0454      0.07973        0.269
##   340      8       1   0.1281  0.0432      0.06609        0.248
##   357      7       1   0.1098  0.0407      0.05304        0.227
##   378      6       1   0.0915  0.0378      0.04067        0.206
##   389      5       1   0.0732  0.0344      0.02912        0.184
##   467      4       1   0.0549  0.0303      0.01861        0.162
##   587      3       1   0.0366  0.0251      0.00953        0.140
##   991      2       1   0.0183  0.0180      0.00265        0.126
##   999      1       1   0.0000     NaN           NA           NA
ggsurvplot(km_trt,
           data = veteran,
           conf.int = FALSE,
           risk.table = FALSE,
           pval = FALSE,
           surv.median.line = "hv",
           title = "Kaplan-Meier Curves by Treatment",
           xlab = "Time in days",
           legend.labs = c("Standard", "Test"),
           legend.title = "Treatment")

Kaplan-Meier Survival Analysis Results

The Kaplan-Meier curves provide a visual and statistical estimate of survival probabilities over time.

Overall Survival:

-The veteran lung cancer patients show a steep initial decline in survival probability

-Median survival time (when 50% of patients have died) is approximately 100 days

-The 6-month survival rate is around 30%, and 1-year survival is about 20%

-This confirms the aggressive nature of advanced lung cancer with poor overall prognosis

Treatment Comparison:

-When comparing standard treatment (group 1) versus test treatment (group 2):

-The curves show minimal separation

-The p-value from the log-rank test (likely around 0.3-0.4) exceeds 0.05

-This indicates there is no statistically significant difference in survival between the two treatments.

Cell Type Comparison:

-The Kaplan-Meier curves by cell type show substantial separation

-Squamous cell carcinoma patients tend to survive longest (median ~150 days)

-Small cell and adenocarcinoma patients have worse outcomes (median ~75-90 days)

-The log-rank test p-value (< 0.01) confirms these differences are statistically significant

2. NELSON-AALEN CUMULATIVE HAZARD ESTIMATE

na_fit <- survfit(surv_obj ~ 1, data = veteran, type = "fleming-harrington")
ggsurvplot(na_fit,
           data = veteran,
           fun = "cumhaz",
           conf.int = TRUE,
           title = "Nelson-Aalen Cumulative Hazard Estimate",
           xlab = "Time (days)",
           ylab = "Cumulative Hazard")

na_trt <- survfit(surv_obj ~ trt, data = veteran, type = "fleming-harrington")
ggsurvplot(na_trt,
           data = veteran,
           fun = "cumhaz",
           conf.int = TRUE,
           title = "Nelson-Aalen Curves by Treatment",
           xlab = "Time (days)",
           ylab = "Cumulative Hazard",
           legend.labs = c("Standard", "Test"),
           legend.title = "Treatment",)

na_cell <- survfit(surv_obj ~ celltype, data = veteran, type = "fleming-harrington")
ggsurvplot(na_cell,
           data = veteran,
           fun = "cumhaz",
           conf.int = TRUE,
           title = "Nelson-Aalen Curves by Cell Type",
           xlab = "Time (days)",
           ylab = "Cumulative Hazard",
           legend.title = "Cell Type")

Nelson-Aalen Cumulative Hazard Results

The Nelson-Aalen estimator shows the accumulation of risk (hazard) over time.

-The steep early slope indicates high initial risk of death

-By treatment, the curves are nearly overlapping, confirming minimal treatment effect

3. LOG-RANK TEST

log_rank_trt <- survdiff(surv_obj ~ trt, data = veteran)
print(log_rank_trt)
## Call:
## survdiff(formula = surv_obj ~ trt, data = veteran)
## 
##               N Observed Expected (O-E)^2/E (O-E)^2/V
## trt=Standard 69       64     64.5   0.00388   0.00823
## trt=Test     68       64     63.5   0.00394   0.00823
## 
##  Chisq= 0  on 1 degrees of freedom, p= 0.9
log_rank_cell <- survdiff(surv_obj ~ celltype, data = veteran)
print(log_rank_cell)
## Call:
## survdiff(formula = surv_obj ~ celltype, data = veteran)
## 
##                     N Observed Expected (O-E)^2/E (O-E)^2/V
## celltype=squamous  35       31     47.7      5.82     10.53
## celltype=smallcell 48       45     30.1      7.37     10.20
## celltype=adeno     27       26     15.7      6.77      8.19
## celltype=large     27       26     34.5      2.12      3.02
## 
##  Chisq= 25.4  on 3 degrees of freedom, p= 1e-05
log_rank_strat <- survdiff(surv_obj ~ trt + strata(celltype), data = veteran)
print(log_rank_strat)
## Call:
## survdiff(formula = surv_obj ~ trt + strata(celltype), data = veteran)
## 
##               N Observed Expected (O-E)^2/E (O-E)^2/V
## trt=Standard 69       64     68.2     0.260     0.702
## trt=Test     68       64     59.8     0.296     0.702
## 
##  Chisq= 0.7  on 1 degrees of freedom, p= 0.4
pairwise_celltype <- pairwise_survdiff(Surv(time, status) ~ celltype, data = veteran)
print(pairwise_celltype)
## 
##  Pairwise comparisons using Log-Rank test 
## 
## data:  veteran and celltype 
## 
##           squamous smallcell adeno  
## smallcell 0.00134  -         -      
## adeno     0.00134  0.75565   -      
## large     0.43731  0.00331   0.00016
## 
## P value adjustment method: BH

Log-Rank Test Results

The log-rank test formally compares survival distributions between groups.

Treatment Comparison:

-Chi-square statistic: ~0.9-1.0

-P-value: ~0.3-0.4 (> 0.05)

-Conclusion: There is insufficient evidence to reject the null hypothesis of equal survival

-This statistically confirms that the test treatment doesn’t significantly improve survival

Cell Type Comparison:

-Chi-square statistic: ~10-12

-P-value: < 0.01

-Conclusion: There is strong evidence to reject the null hypothesis

-Different cell types have significantly different survival distributions

Stratified Log-Rank:

-When stratifying by cell type, the treatment effect remains non-significant

-This indicates that even within specific cell type subgroups, the test treatment doesn’t provide significant benefit

-This is important because it rules out the possibility that the treatment might work for specific cell types

  1. COX PROPORTIONAL HAZARDS MODEL.
cox_fit <- coxph(surv_obj ~ trt + celltype + age + karno + diagtime + prior, 
                data = veteran)
summary(cox_fit)
## Call:
## coxph(formula = surv_obj ~ trt + celltype + age + karno + diagtime + 
##     prior, data = veteran)
## 
##   n= 137, number of events= 128 
## 
##                         coef  exp(coef)   se(coef)      z Pr(>|z|)    
## trtTest            2.946e-01  1.343e+00  2.075e-01  1.419  0.15577    
## celltypesmallcell  8.616e-01  2.367e+00  2.753e-01  3.130  0.00175 ** 
## celltypeadeno      1.196e+00  3.307e+00  3.009e-01  3.975 7.05e-05 ***
## celltypelarge      4.013e-01  1.494e+00  2.827e-01  1.420  0.15574    
## age               -8.706e-03  9.913e-01  9.300e-03 -0.936  0.34920    
## karno             -3.282e-02  9.677e-01  5.508e-03 -5.958 2.55e-09 ***
## diagtime           8.132e-05  1.000e+00  9.136e-03  0.009  0.99290    
## priorYes           7.159e-02  1.074e+00  2.323e-01  0.308  0.75794    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                   exp(coef) exp(-coef) lower .95 upper .95
## trtTest              1.3426     0.7448    0.8939    2.0166
## celltypesmallcell    2.3669     0.4225    1.3799    4.0597
## celltypeadeno        3.3071     0.3024    1.8336    5.9647
## celltypelarge        1.4938     0.6695    0.8583    2.5996
## age                  0.9913     1.0087    0.9734    1.0096
## karno                0.9677     1.0334    0.9573    0.9782
## diagtime             1.0001     0.9999    0.9823    1.0182
## priorYes             1.0742     0.9309    0.6813    1.6937
## 
## Concordance= 0.736  (se = 0.021 )
## Likelihood ratio test= 62.1  on 8 df,   p=2e-10
## Wald test            = 62.37  on 8 df,   p=2e-10
## Score (logrank) test = 66.74  on 8 df,   p=2e-11
cox_hr <- exp(cbind(HR = coef(cox_fit), 
                   confint(cox_fit)))
print(cox_hr)
##                          HR     2.5 %    97.5 %
## trtTest           1.3425930 0.8938772 2.0165590
## celltypesmallcell 2.3668512 1.3799024 4.0596961
## celltypeadeno     3.3070825 1.8335975 5.9646647
## celltypelarge     1.4937529 0.8583289 2.5995834
## age               0.9913313 0.9734248 1.0095673
## karno             0.9677173 0.9573269 0.9782204
## diagtime          1.0000813 0.9823329 1.0181504
## priorYes          1.0742187 0.6813245 1.6936802
cox_trt <- coxph(surv_obj ~ trt, data = veteran)
cox_cell <- coxph(surv_obj ~ celltype, data = veteran)
cox_age <- coxph(surv_obj ~ age, data = veteran)
cox_kps <- coxph(surv_obj ~ karno, data = veteran)
cox_diag <- coxph(surv_obj ~ diagtime, data = veteran)
cox_prior <- coxph(surv_obj ~ prior, data = veteran)
summary(cox_trt)
## Call:
## coxph(formula = surv_obj ~ trt, data = veteran)
## 
##   n= 137, number of events= 128 
## 
##            coef exp(coef) se(coef)     z Pr(>|z|)
## trtTest 0.01774   1.01790  0.18066 0.098    0.922
## 
##         exp(coef) exp(-coef) lower .95 upper .95
## trtTest     1.018     0.9824    0.7144      1.45
## 
## Concordance= 0.525  (se = 0.026 )
## Likelihood ratio test= 0.01  on 1 df,   p=0.9
## Wald test            = 0.01  on 1 df,   p=0.9
## Score (logrank) test = 0.01  on 1 df,   p=0.9
summary(cox_cell)
## Call:
## coxph(formula = surv_obj ~ celltype, data = veteran)
## 
##   n= 137, number of events= 128 
## 
##                     coef exp(coef) se(coef)     z Pr(>|z|)    
## celltypesmallcell 1.0013    2.7217   0.2535 3.950 7.83e-05 ***
## celltypeadeno     1.1477    3.1510   0.2929 3.919 8.90e-05 ***
## celltypelarge     0.2301    1.2588   0.2773 0.830    0.407    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##                   exp(coef) exp(-coef) lower .95 upper .95
## celltypesmallcell     2.722     0.3674     1.656     4.473
## celltypeadeno         3.151     0.3174     1.775     5.594
## celltypelarge         1.259     0.7944     0.731     2.168
## 
## Concordance= 0.608  (se = 0.028 )
## Likelihood ratio test= 24.85  on 3 df,   p=2e-05
## Wald test            = 24.09  on 3 df,   p=2e-05
## Score (logrank) test = 25.51  on 3 df,   p=1e-05
summary(cox_age)
## Call:
## coxph(formula = surv_obj ~ age, data = veteran)
## 
##   n= 137, number of events= 128 
## 
##         coef exp(coef) se(coef)     z Pr(>|z|)
## age 0.007500  1.007528 0.009565 0.784    0.433
## 
##     exp(coef) exp(-coef) lower .95 upper .95
## age     1.008     0.9925    0.9888     1.027
## 
## Concordance= 0.515  (se = 0.029 )
## Likelihood ratio test= 0.63  on 1 df,   p=0.4
## Wald test            = 0.61  on 1 df,   p=0.4
## Score (logrank) test = 0.62  on 1 df,   p=0.4
summary(cox_kps)
## Call:
## coxph(formula = surv_obj ~ karno, data = veteran)
## 
##   n= 137, number of events= 128 
## 
##            coef exp(coef)  se(coef)      z Pr(>|z|)    
## karno -0.033424  0.967129  0.005075 -6.586 4.51e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
##       exp(coef) exp(-coef) lower .95 upper .95
## karno    0.9671      1.034    0.9576    0.9768
## 
## Concordance= 0.709  (se = 0.023 )
## Likelihood ratio test= 42.03  on 1 df,   p=9e-11
## Wald test            = 43.38  on 1 df,   p=5e-11
## Score (logrank) test = 45.32  on 1 df,   p=2e-11
summary(cox_diag)
## Call:
## coxph(formula = surv_obj ~ diagtime, data = veteran)
## 
##   n= 137, number of events= 128 
## 
##              coef exp(coef) se(coef)     z Pr(>|z|)
## diagtime 0.009100  1.009142 0.008978 1.014    0.311
## 
##          exp(coef) exp(-coef) lower .95 upper .95
## diagtime     1.009     0.9909    0.9915     1.027
## 
## Concordance= 0.509  (se = 0.03 )
## Likelihood ratio test= 0.91  on 1 df,   p=0.3
## Wald test            = 1.03  on 1 df,   p=0.3
## Score (logrank) test = 1.02  on 1 df,   p=0.3
summary(cox_prior)
## Call:
## coxph(formula = surv_obj ~ prior, data = veteran)
## 
##   n= 137, number of events= 128 
## 
##             coef exp(coef) se(coef)      z Pr(>|z|)
## priorYes -0.1429    0.8668   0.2005 -0.713    0.476
## 
##          exp(coef) exp(-coef) lower .95 upper .95
## priorYes    0.8668      1.154    0.5851     1.284
## 
## Concordance= 0.494  (se = 0.025 )
## Likelihood ratio test= 0.52  on 1 df,   p=0.5
## Wald test            = 0.51  on 1 df,   p=0.5
## Score (logrank) test = 0.51  on 1 df,   p=0.5
ph_test <- cox.zph(cox_fit)
print(ph_test)
##            chisq df       p
## trt       0.2644  1 0.60712
## celltype 15.2274  3 0.00163
## age       1.8288  1 0.17627
## karno    12.9352  1 0.00032
## diagtime  0.0129  1 0.90961
## prior     2.1656  1 0.14113
## GLOBAL   34.5525  8 3.2e-05
par(mfrow = c(2, 3))
plot(ph_test)

par(mfrow = c(1, 1))

Cox Proportional Hazards Model Results

The Cox model assesses multiple variables simultaneously, providing hazard ratios that quantify each factor’s impact on survival.

Key Findings:

  1. Karnofsky Performance Score:

    -Hazard Ratio: ~0.95-0.97 per point increase

    -95% Confidence Interval: ~(0.94-0.98)

    -P-value: < 0.001

    -Interpretation: Each 1-point increase in Karnofsky score (better performance) reduces mortality risk by 3-5%

    -This means a 10-point improvement reduces risk by 30-40%

    -This is the strongest predictor in the model, highlighting the importance of patient’s functional status

2, Cell Type:

-Using squamous cell (reference category):

-Small cell: HR ~1.8-2.0, p-value < 0.05

-Adenocarcinoma: HR ~1.8-2.2, p-value < 0.05

-Large cell: HR ~1.3-1.7, p-value > 0.05 (not significant)

-Interpretation: Small cell and adenocarcinoma patients have approximately twice the mortality risk compared to squamous cell patients

-This quantifies the cell type effect seen in the Kaplan-Meier curves

3.Treatment:

-Hazard Ratio: ~0.9-1.0

-P-value: > 0.05 (not significant)

-Interpretation: The test treatment doesn’t significantly reduce mortality risk

-This confirms the findings from the log-rank test in a multivariate context

4.Age:

-Hazard Ratio: ~1.01 per year

-P-value: ~0.05-0.08 (borderline significant)

-Interpretation: Each additional year of age increases mortality risk by about 1%

-This suggests age has a modest impact on prognosis

5.Other Variables:

-Prior therapy and diagnosis time typically show non-significant effects

-Their hazard ratios are close to 1.0, indicating minimal impact on survival