DATA: German Breast Cancer Study

GBCD = data.frame(read.csv("gbcs_short.csv"))
head(GBCD)
##   id meno horm size grade nodes rectime censrec prog estr
## 1  1    1    1   18     3     5    1337       1    1    1
## 2  2    1    1   20     1     1    1420       1    1    0
## 3  3    1    1   30     2     1    1279       1    1    1
## 4  4    1    1   24     1     3     148       0    1    0
## 5  5    2    2   19     2     1    1863       0    0    0
## 6  6    2    2   56     1     3    1933       0    1    1
str(GBCD)
## 'data.frame':    686 obs. of  10 variables:
##  $ id     : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ meno   : int  1 1 1 1 2 2 2 2 1 2 ...
##  $ horm   : int  1 1 1 1 2 2 1 2 1 2 ...
##  $ size   : int  18 20 30 24 19 56 52 22 30 20 ...
##  $ grade  : int  3 1 2 1 2 1 2 2 2 2 ...
##  $ nodes  : int  5 1 1 3 1 3 9 2 1 1 ...
##  $ rectime: int  1337 1420 1279 148 1863 1933 358 2372 2563 2372 ...
##  $ censrec: int  1 1 1 0 0 0 1 1 0 0 ...
##  $ prog   : int  1 1 1 1 0 1 0 0 1 1 ...
##  $ estr   : int  1 0 1 0 0 1 1 1 0 1 ...

1.Using the Kaplan-Meier method, solve for the survival probabilities of patients regardless of the treatment assignment.

library(survival)
library(survminer)
#For Conversion:
with(GBCD, Surv(rectime, censrec))
##   [1] 1337  1420  1279   148+ 1863+ 1933+  358  2372  2563+ 2372+ 1989   579 
##  [13] 1043  2234+ 2297+ 2014+  518  1763   889   357   547  1722+ 2372+  251 
##  [25] 1959+ 1897+  348   275  1329  1193   698   436   552  2551+  754   819 
##  [37] 1280   663+  722   322+ 1150   446  1855+  238  1838+ 1826+ 2353+ 2471+
##  [49]  893  2093   740+  632  1866+  491  1918    72  2556+ 1753   417   956 
##  [61] 1846+ 2449+ 2286   456   536   612  2034  1990  1976+ 2539+ 2467+  876 
##  [73] 2132+  426   537  2217+  296+ 2320+  795   867   755  1388  1387   535 
##  [85] 1653+ 1904+ 1868+ 1767+  855  1157  2380+ 1679   498  2138+ 2175+  563 
##  [97]   46+ 2144+  344   945+ 1905+ 2659+ 1977  2401+ 1499+ 1856+  595  2148+
## [109] 2126+ 1975  2438+ 2233+  286  2170+  729  1449   991   481  1814  2018 
## [121]  712  1869+  307   983   120  1525  1680+ 1730   805  2388+  559  1977+
## [133]  308  1965+  548   293  2017+ 1152+ 1401+ 2128+ 1965+ 2161+ 1183  1108 
## [145] 2065+  918+  745  1283+ 1527+  285  1306   797  1441+ 2612+  956  1637+
## [157] 2456+ 1641  1717+ 1858+ 2049+ 2388+ 2296+ 1884+ 1059   564  2239+ 2237+
## [169]  476  1514+ 1617+ 1094   784  1760+ 1013+  779+ 1807   772  2456  2205+
## [181]  544   336  2057+  575  2011+ 2010+ 2009+ 1984+ 2030  1002  1280   338 
## [193]  533  1182+   71+  114+   63+ 1655+  857   369  1627+  855  2370+  853+
## [205]  692+  475  1861+ 1080  1521  1693+  859+ 1109+ 1192  1806   500  1814 
## [217]  890  1114+ 2271+   17+  964   540   747   650   168+ 1169+ 1675  1862+
## [229]  629+  181   343   936+  195+  503   827  1427+ 1722+ 1692+  177+  679 
## [241] 1164   350   578  1598+  491  1366  1225   338  2227+ 1601  1841+ 2177+
## [253] 2052+ 1140   799  1105   548   227   448  2172+ 2161+  471  2014+  554 
## [265] 1246  1926+ 1207  1852+ 1459  2237+  933+ 1481  1807+  542  1441+ 1277+
## [277] 1486+ 1502  1922+ 2048+  600  1765+  491   305  2195+  758+  648   761+
## [289]  596+  195   473  1528   169   272   731  2059+  415  1120   316   637 
## [301]  186+  769   727  1701  2015  1956+  945  2153+  838   113  1833+ 2056+
## [313] 1729+ 2024+ 2039  2027+ 2007+  973+ 2156+ 1499+  424+  859   180  1625+
## [325] 1938+ 1343   646  2192+  502  1675+   42+  410   624  1560+  455  1629+
## [337]  529  1820+ 1756+  375  1323+ 1233+  986+  650+  577   184  1840+  273+
## [349]  177   545  1185+  631+ 1853+ 1854+ 1645+  544  1666+  353  1167+  495 
## [361]  967+ 1720+  598   392  1502+  229+ 1838+ 1833+  550   426  1834+ 2030+
## [373]  573  1666+ 1979+ 1703+  670  1791+ 1685+  191   370   173   242   420 
## [385]  247   888+  622   806+ 1163+ 1721+  741+  160   970+  892+  753+ 1703+
## [397] 1720+ 1355+ 1603+  476  1350+ 1341+ 1093+  792+  586  1434+   67+  623+
## [409] 1582+ 1771+  960   571   747+ 1578+  732   460  1208+  730   722+  717+
## [421] 1093  2051+  370   861  1587  1589  1463  1826+ 1231+ 1117+  836  1222+
## [433] 1981+  624   742  1818+ 1493  1432+  801  1786+ 1847+ 2009+ 1926+ 1818+
## [445] 1100+ 1499+ 1253  1789+ 1707+ 1714+ 1717+  329   854+  177   281   205 
## [457]  751+  629  1722+  241  1352  1702+ 1222+ 1089+ 1243+  995+ 1088+ 1842+
## [469] 1821+ 1371   707  1743+ 1781+  865    57+ 1152+ 1460  1434+ 1604+  772+
## [481] 1146   371   883  1735+  554  1174  1250+  530  1502+ 1364+ 1170  1729+
## [493] 1642+  877+  515   272   891  1356+ 1352+ 1077+  675   359  1645+ 1356+
## [505] 1632+  967+ 1091+  918   557  1219   438  1624+ 1036   359   171  1490+
## [517]  233  1240+ 1751+ 1878+ 1684  1701+ 1701+ 1693+  379  1105   548  1296 
## [529] 1483+  675+  285  1472+ 1363   420   982  1459+ 1192+ 1264+ 1095+ 1078+
## [541] 1624+ 1600+  385  1475+ 1171+ 1751+ 1756+  798+  940+  766+  790  1340+
## [553]  490  1557+  981  1094+ 1730+ 1483+  714   372  1331+  394   652+  657+
## [565]  567+  429+  566+   15+  310+ 1296+  488+ 1505+  776  1570+ 1469+ 1472+
## [577] 1342+ 1349+ 1162  1342+  797  1232+  959  1351+  486   733+  526+  463+
## [589]  529+  623+  546+  213+  276+  942+  570+ 1177+ 1113+  288   723+  403 
## [601] 1443+ 1317+ 1218  1358+  360   550  1435+  541+ 1329+ 1357+  552   870+
## [613]  859   734+  687   308    98   368+  432+  319+   65+ 1343+  748   737+
## [625]  461+  465   842   918+  374  1089+  223  1212+ 1119+  974+ 1230+ 1205+
## [637] 1090+ 1095+  449   972+  825+  525   762   175   855+  740+ 1090  1219+
## [649] 1195+  338   628+ 1125+  916+  972+  553+  662   594   828+  651+  637+
## [661]  615+  740+ 1062+    8+  936+  867+  249   281   758+  377   969+  974+
## [673]  866   504   721+  594   841+  695+   16+   29+   18+   17+  857+  768+
## [685]  858+  770+
#converting to survival time

#Estimation of Survival Function Method Used: Kaplan-Meier Method
model <- survfit(with(GBCD, Surv(rectime, censrec)) ~ 1)
summary(model)
## Call: survfit(formula = with(GBCD, Surv(rectime, censrec)) ~ 1)
## 
##  time n.risk n.event survival std.err lower 95% CI upper 95% CI
##    72    672       1    0.999 0.00149        0.996        1.000
##    98    671       1    0.997 0.00210        0.993        1.000
##   113    670       1    0.996 0.00257        0.991        1.000
##   120    668       1    0.994 0.00297        0.988        1.000
##   160    666       1    0.993 0.00332        0.986        0.999
##   169    664       1    0.991 0.00363        0.984        0.998
##   171    663       1    0.990 0.00392        0.982        0.997
##   173    662       1    0.988 0.00419        0.980        0.996
##   175    661       1    0.987 0.00445        0.978        0.995
##   177    660       2    0.984 0.00491        0.974        0.993
##   180    657       1    0.982 0.00512        0.972        0.992
##   181    656       1    0.981 0.00533        0.970        0.991
##   184    655       1    0.979 0.00553        0.968        0.990
##   191    653       1    0.978 0.00572        0.966        0.989
##   195    652       1    0.976 0.00590        0.965        0.988
##   205    650       1    0.975 0.00608        0.963        0.987
##   223    648       1    0.973 0.00626        0.961        0.985
##   227    647       1    0.972 0.00643        0.959        0.984
##   233    645       1    0.970 0.00659        0.957        0.983
##   238    644       1    0.969 0.00675        0.955        0.982
##   241    643       1    0.967 0.00691        0.954        0.981
##   242    642       1    0.966 0.00706        0.952        0.979
##   247    641       1    0.964 0.00720        0.950        0.978
##   249    640       1    0.963 0.00735        0.948        0.977
##   251    639       1    0.961 0.00749        0.946        0.976
##   272    638       2    0.958 0.00776        0.943        0.973
##   275    635       1    0.957 0.00790        0.941        0.972
##   281    633       2    0.953 0.00816        0.938        0.970
##   285    631       2    0.950 0.00841        0.934        0.967
##   286    629       1    0.949 0.00853        0.932        0.966
##   288    628       1    0.947 0.00865        0.931        0.965
##   293    627       1    0.946 0.00876        0.929        0.963
##   305    625       1    0.944 0.00888        0.927        0.962
##   307    624       1    0.943 0.00899        0.925        0.961
##   308    623       2    0.940 0.00922        0.922        0.958
##   316    620       1    0.938 0.00932        0.920        0.957
##   329    617       1    0.937 0.00943        0.919        0.956
##   336    616       1    0.935 0.00954        0.917        0.954
##   338    615       3    0.931 0.00985        0.912        0.950
##   343    612       1    0.929 0.00995        0.910        0.949
##   344    611       1    0.928 0.01005        0.908        0.948
##   348    610       1    0.926 0.01015        0.907        0.946
##   350    609       1    0.925 0.01024        0.905        0.945
##   353    608       1    0.923 0.01034        0.903        0.944
##   357    607       1    0.922 0.01043        0.901        0.942
##   358    606       1    0.920 0.01053        0.900        0.941
##   359    605       2    0.917 0.01071        0.896        0.938
##   360    603       1    0.916 0.01080        0.895        0.937
##   369    601       1    0.914 0.01089        0.893        0.936
##   370    600       2    0.911 0.01106        0.890        0.933
##   371    598       1    0.909 0.01115        0.888        0.932
##   372    597       1    0.908 0.01123        0.886        0.930
##   374    596       1    0.906 0.01132        0.885        0.929
##   375    595       1    0.905 0.01140        0.883        0.928
##   377    594       1    0.903 0.01148        0.881        0.926
##   379    593       1    0.902 0.01156        0.879        0.925
##   385    592       1    0.900 0.01164        0.878        0.923
##   392    591       1    0.899 0.01172        0.876        0.922
##   394    590       1    0.897 0.01180        0.874        0.921
##   403    589       1    0.896 0.01188        0.873        0.919
##   410    588       1    0.894 0.01196        0.871        0.918
##   415    587       1    0.893 0.01203        0.869        0.917
##   417    586       1    0.891 0.01211        0.868        0.915
##   420    585       2    0.888 0.01226        0.864        0.912
##   426    582       2    0.885 0.01240        0.861        0.910
##   436    578       1    0.884 0.01248        0.859        0.908
##   438    577       1    0.882 0.01255        0.858        0.907
##   446    576       1    0.880 0.01262        0.856        0.906
##   448    575       1    0.879 0.01269        0.854        0.904
##   449    574       1    0.877 0.01276        0.853        0.903
##   455    573       1    0.876 0.01283        0.851        0.901
##   456    572       1    0.874 0.01290        0.849        0.900
##   460    571       1    0.873 0.01297        0.848        0.899
##   465    568       1    0.871 0.01303        0.846        0.897
##   471    567       1    0.870 0.01310        0.844        0.896
##   473    566       1    0.868 0.01317        0.843        0.894
##   475    565       1    0.867 0.01323        0.841        0.893
##   476    564       2    0.864 0.01337        0.838        0.890
##   481    562       1    0.862 0.01343        0.836        0.889
##   486    561       1    0.861 0.01349        0.834        0.887
##   490    559       1    0.859 0.01356        0.833        0.886
##   491    558       3    0.854 0.01374        0.828        0.882
##   495    555       1    0.853 0.01380        0.826        0.880
##   498    554       1    0.851 0.01387        0.825        0.879
##   500    553       1    0.850 0.01393        0.823        0.878
##   502    552       1    0.848 0.01398        0.821        0.876
##   503    551       1    0.847 0.01404        0.820        0.875
##   504    550       1    0.845 0.01410        0.818        0.873
##   515    549       1    0.844 0.01416        0.816        0.872
##   518    548       1    0.842 0.01422        0.815        0.870
##   525    547       1    0.841 0.01428        0.813        0.869
##   529    545       1    0.839 0.01433        0.811        0.868
##   530    543       1    0.837 0.01439        0.810        0.866
##   533    542       1    0.836 0.01445        0.808        0.865
##   535    541       1    0.834 0.01450        0.806        0.863
##   536    540       1    0.833 0.01456        0.805        0.862
##   537    539       1    0.831 0.01461        0.803        0.860
##   540    538       1    0.830 0.01467        0.801        0.859
##   542    536       1    0.828 0.01472        0.800        0.858
##   544    535       2    0.825 0.01483        0.797        0.855
##   545    533       1    0.824 0.01488        0.795        0.853
##   547    531       1    0.822 0.01493        0.793        0.852
##   548    530       3    0.817 0.01509        0.788        0.847
##   550    527       2    0.814 0.01519        0.785        0.845
##   552    525       2    0.811 0.01529        0.782        0.842
##   554    522       2    0.808 0.01539        0.778        0.839
##   557    520       1    0.806 0.01543        0.777        0.837
##   559    519       1    0.805 0.01548        0.775        0.836
##   563    518       1    0.803 0.01553        0.773        0.834
##   564    517       1    0.802 0.01558        0.772        0.833
##   571    513       1    0.800 0.01563        0.770        0.831
##   573    512       1    0.799 0.01567        0.769        0.830
##   575    511       1    0.797 0.01572        0.767        0.829
##   577    510       1    0.796 0.01577        0.765        0.827
##   578    509       1    0.794 0.01581        0.764        0.826
##   579    508       1    0.792 0.01586        0.762        0.824
##   586    507       1    0.791 0.01591        0.760        0.823
##   594    506       2    0.788 0.01600        0.757        0.820
##   595    504       1    0.786 0.01604        0.755        0.818
##   598    502       1    0.785 0.01608        0.754        0.817
##   600    501       1    0.783 0.01613        0.752        0.815
##   612    500       1    0.781 0.01617        0.750        0.814
##   622    498       1    0.780 0.01622        0.749        0.812
##   624    495       2    0.777 0.01630        0.745        0.809
##   629    492       1    0.775 0.01635        0.744        0.808
##   632    489       1    0.774 0.01639        0.742        0.806
##   637    488       1    0.772 0.01643        0.740        0.805
##   646    486       1    0.770 0.01647        0.739        0.803
##   648    485       1    0.769 0.01652        0.737        0.802
##   650    484       1    0.767 0.01656        0.735        0.800
##   662    479       1    0.766 0.01660        0.734        0.799
##   670    477       1    0.764 0.01664        0.732        0.797
##   675    476       1    0.762 0.01669        0.730        0.796
##   679    474       1    0.761 0.01673        0.729        0.794
##   687    473       1    0.759 0.01677        0.727        0.793
##   698    470       1    0.758 0.01681        0.725        0.791
##   707    469       1    0.756 0.01685        0.724        0.790
##   712    468       1    0.754 0.01689        0.722        0.788
##   714    467       1    0.753 0.01694        0.720        0.787
##   722    464       1    0.751 0.01698        0.719        0.785
##   727    461       1    0.749 0.01702        0.717        0.784
##   729    460       1    0.748 0.01706        0.715        0.782
##   730    459       1    0.746 0.01710        0.713        0.781
##   731    458       1    0.745 0.01714        0.712        0.779
##   732    457       1    0.743 0.01718        0.710        0.777
##   742    449       1    0.741 0.01722        0.708        0.776
##   745    448       1    0.740 0.01726        0.707        0.774
##   747    447       1    0.738 0.01730        0.705        0.773
##   748    445       1    0.736 0.01734        0.703        0.771
##   754    442       1    0.735 0.01738        0.701        0.770
##   755    441       1    0.733 0.01742        0.700        0.768
##   762    437       1    0.731 0.01746        0.698        0.766
##   769    434       1    0.730 0.01750        0.696        0.765
##   772    432       1    0.728 0.01755        0.694        0.763
##   776    430       1    0.726 0.01759        0.693        0.762
##   784    428       1    0.725 0.01763        0.691        0.760
##   790    427       1    0.723 0.01767        0.689        0.758
##   795    425       1    0.721 0.01771        0.687        0.757
##   797    424       2    0.718 0.01779        0.684        0.753
##   799    421       1    0.716 0.01783        0.682        0.752
##   801    420       1    0.714 0.01786        0.680        0.750
##   805    419       1    0.713 0.01790        0.678        0.749
##   819    417       1    0.711 0.01794        0.677        0.747
##   827    415       1    0.709 0.01798        0.675        0.745
##   836    413       1    0.708 0.01802        0.673        0.744
##   838    412       1    0.706 0.01806        0.671        0.742
##   842    410       1    0.704 0.01809        0.669        0.740
##   855    407       2    0.701 0.01817        0.666        0.737
##   857    404       1    0.699 0.01821        0.664        0.736
##   859    401       2    0.695 0.01828        0.660        0.732
##   861    398       1    0.694 0.01832        0.659        0.731
##   865    397       1    0.692 0.01836        0.657        0.729
##   866    396       1    0.690 0.01839        0.655        0.727
##   867    395       1    0.688 0.01843        0.653        0.726
##   876    392       1    0.687 0.01847        0.651        0.724
##   883    390       1    0.685 0.01850        0.650        0.722
##   889    388       1    0.683 0.01854        0.648        0.720
##   890    387       1    0.681 0.01857        0.646        0.719
##   891    386       1    0.680 0.01861        0.644        0.717
##   893    384       1    0.678 0.01865        0.642        0.715
##   918    382       1    0.676 0.01868        0.640        0.714
##   945    374       1    0.674 0.01872        0.639        0.712
##   956    372       2    0.671 0.01879        0.635        0.708
##   959    370       1    0.669 0.01883        0.633        0.707
##   960    369       1    0.667 0.01886        0.631        0.705
##   964    368       1    0.665 0.01890        0.629        0.703
##   981    358       1    0.663 0.01894        0.627        0.702
##   982    357       1    0.661 0.01898        0.625        0.700
##   983    356       1    0.660 0.01901        0.623        0.698
##   991    354       1    0.658 0.01905        0.621        0.696
##  1002    352       1    0.656 0.01909        0.620        0.694
##  1036    350       1    0.654 0.01913        0.618        0.693
##  1043    349       1    0.652 0.01916        0.616        0.691
##  1059    348       1    0.650 0.01920        0.614        0.689
##  1080    344       1    0.648 0.01924        0.612        0.687
##  1090    340       1    0.646 0.01927        0.610        0.685
##  1093    337       1    0.645 0.01931        0.608        0.684
##  1094    335       1    0.643 0.01935        0.606        0.682
##  1105    330       2    0.639 0.01943        0.602        0.678
##  1108    328       1    0.637 0.01947        0.600        0.676
##  1120    322       1    0.635 0.01951        0.598        0.674
##  1140    320       1    0.633 0.01955        0.596        0.672
##  1146    319       1    0.631 0.01958        0.594        0.670
##  1150    318       1    0.629 0.01962        0.592        0.669
##  1157    315       1    0.627 0.01966        0.589        0.667
##  1162    314       1    0.625 0.01970        0.587        0.665
##  1164    312       1    0.623 0.01974        0.585        0.663
##  1170    309       1    0.621 0.01978        0.583        0.661
##  1174    307       1    0.619 0.01982        0.581        0.659
##  1183    304       1    0.617 0.01986        0.579        0.657
##  1192    302       1    0.615 0.01989        0.577        0.655
##  1193    300       1    0.613 0.01993        0.575        0.653
##  1207    297       1    0.611 0.01997        0.573        0.651
##  1218    294       1    0.609 0.02001        0.571        0.649
##  1219    293       1    0.606 0.02005        0.568        0.647
##  1225    289       1    0.604 0.02009        0.566        0.645
##  1246    282       1    0.602 0.02013        0.564        0.643
##  1253    280       1    0.600 0.02018        0.562        0.641
##  1279    277       1    0.598 0.02022        0.560        0.639
##  1280    276       2    0.594 0.02030        0.555        0.635
##  1296    273       1    0.591 0.02035        0.553        0.633
##  1306    271       1    0.589 0.02039        0.551        0.631
##  1329    268       1    0.587 0.02043        0.548        0.628
##  1337    265       1    0.585 0.02047        0.546        0.626
##  1343    260       1    0.583 0.02052        0.544        0.624
##  1352    255       1    0.580 0.02056        0.541        0.622
##  1363    248       1    0.578 0.02061        0.539        0.620
##  1366    246       1    0.576 0.02066        0.536        0.618
##  1371    245       1    0.573 0.02071        0.534        0.615
##  1387    244       1    0.571 0.02076        0.532        0.613
##  1388    243       1    0.569 0.02081        0.529        0.611
##  1420    241       1    0.566 0.02085        0.527        0.609
##  1449    232       1    0.564 0.02091        0.524        0.606
##  1459    231       1    0.561 0.02096        0.522        0.604
##  1460    229       1    0.559 0.02101        0.519        0.602
##  1463    228       1    0.556 0.02106        0.517        0.599
##  1481    223       1    0.554 0.02111        0.514        0.597
##  1493    218       1    0.551 0.02117        0.511        0.594
##  1502    214       1    0.549 0.02122        0.509        0.592
##  1521    209       1    0.546 0.02128        0.506        0.590
##  1525    208       1    0.544 0.02134        0.503        0.587
##  1528    206       1    0.541 0.02140        0.501        0.585
##  1587    200       1    0.538 0.02147        0.498        0.582
##  1589    199       1    0.535 0.02153        0.495        0.579
##  1601    196       1    0.533 0.02159        0.492        0.577
##  1641    185       1    0.530 0.02167        0.489        0.574
##  1675    177       1    0.527 0.02175        0.486        0.571
##  1679    175       1    0.524 0.02183        0.483        0.568
##  1684    173       1    0.521 0.02191        0.480        0.566
##  1701    168       1    0.518 0.02200        0.476        0.563
##  1730    150       1    0.514 0.02212        0.473        0.560
##  1753    144       1    0.511 0.02226        0.469        0.556
##  1763    140       1    0.507 0.02240        0.465        0.553
##  1806    132       1    0.503 0.02255        0.461        0.549
##  1807    131       1    0.499 0.02271        0.457        0.546
##  1814    129       2    0.492 0.02300        0.449        0.539
##  1918     94       1    0.486 0.02335        0.443        0.534
##  1975     84       1    0.481 0.02378        0.436        0.530
##  1977     82       1    0.475 0.02420        0.430        0.525
##  1989     77       1    0.469 0.02466        0.423        0.520
##  1990     76       1    0.462 0.02509        0.416        0.514
##  2015     68       1    0.456 0.02563        0.408        0.509
##  2018     66       1    0.449 0.02615        0.400        0.503
##  2030     63       1    0.442 0.02669        0.392        0.497
##  2034     61       1    0.434 0.02722        0.384        0.491
##  2039     60       1    0.427 0.02771        0.376        0.485
##  2093     51       1    0.419 0.02840        0.367        0.478
##  2286     25       1    0.402 0.03182        0.344        0.469
##  2372     19       1    0.381 0.03651        0.316        0.460
##  2456     10       1    0.343 0.04884        0.259        0.453
#Plot model
plot(model)
abline(c(0.5,0), lty = 3, col = "red")
title("Survival Probabilities of patient: Kaplan-mier method")

The above graph indicates that there is an estimated 99.7% probability of disease recurrence for longer than 100 days, wile 85% for longer than 500%, 65.8% for longer than 1000 days, 42.6% for longer than 2,000 days, while there is about 34.3% probability for longer than 2456 days. In addition, there is about 1087 days for the median time to event of breast cancer patients.

2. For each of the comparison below, identify the most appropriate test and do the analysis.

Tests:
Two-group Logrank Tests
Two-group Wilcoxon-Gehan Tests
Multi-group Logrank Tests
Logrank Tests for Ordered Groups
Stratified Logrank Tests

a. survival times between menopause status
#LogRank Test
M <- survfit(Surv(rectime, censrec) ~ meno, data = GBCD)
M
## Call: survfit(formula = Surv(rectime, censrec) ~ meno, data = GBCD)
## 
##          n events median 0.95LCL 0.95UCL
## meno=1 290    119   2015    1587      NA
## meno=2 396    180   1701    1481    1990
plot(survfit(Surv(rectime,censrec) ~ meno,data = GBCD), 
     col = c("blue", "black"), 
     lwd = c(2,2), 
     mark.time = FALSE)
legend("bottomleft",
       legend = c("1 - No", "2 - Yes"), 
       col = c("blue", "black"), 
       lwd = c(2,2), 
       bty = "n")
abline(c(0.5,0), lty = 3, col = "red")
title("survival times between menopause status")

#test
survdiff(Surv(rectime,censrec) ~ meno,data = GBCD )
## Call:
## survdiff(formula = Surv(rectime, censrec) ~ meno, data = GBCD)
## 
##          N Observed Expected (O-E)^2/E (O-E)^2/V
## meno=1 290      119      124     0.164      0.28
## meno=2 396      180      175     0.115      0.28
## 
##  Chisq= 0.3  on 1 degrees of freedom, p= 0.6

In this case, the two-group log-rank test was used to identify if there is a difference between the survival times of menopause status over time. The result indicates that with Chisq= 0.3 on 1 degrees of freedom, p= 0.6 greater than \(a=0.05\) level of significance. Thus, this means that the true survival function in both status are not different (or similar) since we cannot reject the null hypotheses.Therefore, we state that at 5% level of significance the survival times of the menopause status are equal.

b. survival times between progesterone status
#LogRank Test
P <- survfit(Surv(rectime, censrec) ~ prog, data = GBCD)
P
## Call: survfit(formula = Surv(rectime, censrec) ~ prog, data = GBCD)
## 
##          n events median 0.95LCL 0.95UCL
## prog=0 277    154   1140     842    1387
## prog=1 409    145   2286    1989      NA
plot(survfit(Surv(rectime,censrec) ~ prog,data = GBCD), 
     col = c("blue", "black"), 
     lwd = c(2,2), 
     mark.time = FALSE)
legend("bottomleft",
       legend = c("1 - Positive", "0 - Negative"), 
       col = c("blue", "black"), 
       lwd = c(2,2), 
       bty = "n")
abline(c(0.5,0), lty = 3, col = "red")
title("survival times between progesterone status")

#test
survdiff(Surv(rectime,censrec) ~ prog,data = GBCD )
## Call:
## survdiff(formula = Surv(rectime, censrec) ~ prog, data = GBCD)
## 
##          N Observed Expected (O-E)^2/E (O-E)^2/V
## prog=0 277      154     97.3      33.0      49.3
## prog=1 409      145    201.7      15.9      49.3
## 
##  Chisq= 49.3  on 1 degrees of freedom, p= 2e-12

In this case, we used log rank test since it is a powerful test for detecting differences in survival curves, specifically when the proportional hazards assumption is met. Since the curves do not diverge nor converge over time, then this may be evidence that the proportional hazards assumption is met.The result shows a computed chi-square of 49.3 on 1 degrees of freedom with a p-value = 2e−12 < \(a=0.05\). Thus, the null hypotheses will be rejected and state that the true survival function in both groups are different. Therefore, we conclude that the true survival times between progesterone status are different.

c. survival times across cancer cells grade
G <- survfit(Surv(rectime, censrec) ~ grade, data = GBCD, conf.type = "log") #Greenwood's CI
G
## Call: survfit(formula = Surv(rectime, censrec) ~ grade, data = GBCD, 
##     conf.type = "log")
## 
##           n events median 0.95LCL 0.95UCL
## grade=1  81     18     NA    1990      NA
## grade=2 444    202   1730    1493    2030
## grade=3 161     79   1337     960      NA
plot(survfit(Surv(rectime, censrec) ~ grade, data = GBCD), 
     col = c("blue", "black", "red"), 
     lwd = c(2,2,2,2), 
     mark.time = FALSE)
legend("topright",
       legend = c("3 - low", "2 - medium","1 - high"), 
       col = c("blue", "black", "red"), 
       lwd = c(2,2,2,2), 
       cex = 0.80,
       bty = "n")
abline(c(0.5,0), lty = 3, col = "red")
title("survival times across cancer cells grade")

#multigroup logrank test
survdiff(Surv(rectime, censrec) ~ grade,data = GBCD )
## Call:
## survdiff(formula = Surv(rectime, censrec) ~ grade, data = GBCD)
## 
##           N Observed Expected (O-E)^2/E (O-E)^2/V
## grade=1  81       18     42.2   13.8469    16.159
## grade=2 444      202    198.2    0.0725     0.215
## grade=3 161       79     58.6    7.0788     8.848
## 
##  Chisq= 21.1  on 2 degrees of freedom, p= 3e-05

In this case, we used the logrank test for ordered groups since it is used to test comparison between three or more ordered groups of categorical variables (1-high, 2-medium, 3-low).
The result shows a Chisq= 21.1 on 2 degrees of freedom with p-value = 3e−05 < \(a=0.05\). Therefore, null hypotheses will be rejected which means that the survival times for different groups of cancer cells grade is the equal. Therefore, we can conclude that there is at least one pair of survival times for different groups of cancer cells grade that are different.

d. survival times between estrogen status based on the treatment assignment (hormone or adjuvant)
EH <- survfit(Surv(rectime,censrec) ~ estr + strata(horm), data = GBCD, conf.type = "log") #Greenwood's CI
EH
## Call: survfit(formula = Surv(rectime, censrec) ~ estr + strata(horm), 
##     data = GBCD, conf.type = "log")
## 
##                               n events median 0.95LCL 0.95UCL
## estr=0, strata(horm)=horm=1 181     97   1296     960    1587
## estr=0, strata(horm)=horm=2  91     40   1918    1140      NA
## estr=1, strata(horm)=horm=1 259    108   1814    1528      NA
## estr=1, strata(horm)=horm=2 155     54   2030    1989      NA
plot(EH, 
     col = c("blue", "red", "orange", "black"), 
     lwd = c(2,2,2,2), 
     mark.time = FALSE)
legend("topright",
       legend = c(" Negative ~ No"," Negative ~ Yes",
                  " Positive ~ No"," Positive ~ Yes"), 
       col = c("blue", "red", "orange", "black"), 
       lwd = c(2,2,2,2), 
       cex = 0.80,
       bty = "n")
abline(c(0.5,0), lty = 3, col = "red")
title("survival times between estrogen status based on hormone therapy")

#stratified
survdiff(Surv(rectime,censrec) ~ estr + strata(horm), data = GBCD)
## Call:
## survdiff(formula = Surv(rectime, censrec) ~ estr + strata(horm), 
##     data = GBCD)
## 
##          N Observed Expected (O-E)^2/E (O-E)^2/V
## estr=0 272      137      108      7.68      12.2
## estr=1 414      162      191      4.35      12.2
## 
##  Chisq= 12.2  on 1 degrees of freedom, p= 5e-04

In this case, we used stratified log rank test since we are comparing survival curves of the estrogen status based on the treatment assignment, (hormone or adjuvant).

The results shows that the calculated chi-square value is 12.2 with 1 degrees of freedom, and the p-value is 0.0005 < 0.05 level of significance. Thus, the null hypothesis is rejected, which means that there is difference on the survival times between the estrogen status based on the treatment assignment (hormone or adjuvant). Therefore, we can conclude that the survival times between estrogen status differ in the type of treatments (hormone or adjuvant).

e. survival times based on tumor size
#install.packages("PHInfiniteEstimates")
library(PHInfiniteEstimates)
#trend
GBCD["size"] = cut(GBCD$size, c(0,20, 40, 60, 80,100, 120), 
                      include.lowest=TRUE)
table(GBCD$size)
## 
##    [0,20]   (20,40]   (40,60]   (60,80]  (80,100] (100,120] 
##       180       408        78        16         3         1
attach(GBCD)
survdiff(Surv(rectime,censrec) ~ size, data = GBCD)
## Call:
## survdiff(formula = Surv(rectime, censrec) ~ size, data = GBCD)
## 
##                  N Observed Expected (O-E)^2/E (O-E)^2/V
## size=[0,20]    180       65 8.80e+01    6.0266    8.6418
## size=(20,40]   408      186 1.73e+02    1.0444    2.4854
## size=(40,60]    78       34 3.16e+01    0.1819    0.2040
## size=(60,80]    16       11 5.02e+00    7.1354    7.2702
## size=(80,100]    3        2 1.77e+00    0.0313    0.0315
## size=(100,120]   1        1 7.47e-03  131.8861  132.0834
## 
##  Chisq= 147  on 5 degrees of freedom, p= <2e-16
plot(survfit(Surv(rectime, censrec)~size),
col = c("gray","blue","black","green","brown","orange"),
lwd = c(2,2,2,2,2,2),
mark.time = F)
legend("topright",
legend = unique(size),
col = c("gray","blue","black","green","brown","orange"),
lwd = c(2,2,2,2,2,2,2),
bty = "n")
abline(c(0.5,0), lty = 3, col = "red")
title("survival times based on tumor size")

fit1 <- coxph(Surv(rectime,censrec) ~ size, data = GBCD)
fit1
## Call:
## coxph(formula = Surv(rectime, censrec) ~ size, data = GBCD)
## 
##                   coef exp(coef) se(coef)     z        p
## size(20,40]     0.3837    1.4676   0.1447 2.651 0.008026
## size(40,60]     0.3823    1.4656   0.2123 1.801 0.071686
## size(60,80]     1.0982    2.9987   0.3270 3.358 0.000784
## size(80,100]    0.4255    1.5304   0.7183 0.592 0.553620
## size(100,120]   5.4410  230.6754   1.1239 4.841 1.29e-06
## 
## Likelihood ratio test=21.35  on 5 df, p=0.0006959
## n= 686, number of events= 299
w <- c(-2,-1,0,1,2)
U_t <- w %*% coef(fit1)
V_t <- w %*% fit1$var %*% w
U_t^2/V_t
##         [,1]
## [1,] 18.6459
pchisq(U_t^2/V_t, df=1, lower.tail=FALSE)
##             [,1]
## [1,] 1.57385e-05

In this case, we use trend test since we want to compare the survival curves of more than three ordered groups of tumor size which can be arrange or ordered, with that the magnitude of the differences is relevant. Hence, there will be six group arrangement for the tumor size.

The results show that p-value of 1.57385e-05 or 0.0000157385 < \(a=0.05\) , thus null hypotheses will be rejected which means that the survival times for different groups are not equal. Therefore, we can conclude that there is at least one pairing of survival times for different groups of tumor size which are not equal.

f. survival times based on the number of axillary lymph nodes with metastases
library(survival)
library(survminer)
#trend
GBCD["nodes"] = cut(GBCD$nodes, c(0,20,40, 60), 
                      include.lowest=TRUE)
table(GBCD$nodes)
## 
##  [0,20] (20,40] (40,60] 
##     675      10       1
attach(GBCD)
survdiff(Surv(rectime,censrec) ~ nodes, data = GBCD)
## Call:
## survdiff(formula = Surv(rectime, censrec) ~ nodes, data = GBCD)
## 
##                 N Observed Expected (O-E)^2/E (O-E)^2/V
## nodes=[0,20]  675      290  296.103     0.126    13.031
## nodes=(20,40]  10        9    2.585    15.924    16.117
## nodes=(40,60]   1        0    0.313     0.313     0.313
## 
##  Chisq= 16.4  on 2 degrees of freedom, p= 3e-04
plot(survfit(Surv(rectime, censrec)~nodes),
col = c("red","blue","brown"),
lwd = c(2,2,2,2,2,2),
mark.time = F)
legend("topright",
legend = unique(nodes),
col = c("red","blue","brown"),
lwd = c(2,2,2,2,2,2,2),
bty = "n")
abline(c(0.5,0), lty = 3, col = "red")
title("survival times based on the number of axillary lymph nodes with metastases")

fit2 <- coxph(Surv(rectime,censrec) ~ nodes, data = GBCD)
fit2
## Call:
## coxph(formula = Surv(rectime, censrec) ~ nodes, data = GBCD)
## 
##                    coef  exp(coef)   se(coef)      z        p
## nodes(20,40]  1.276e+00  3.581e+00  3.402e-01  3.750 0.000177
## nodes(40,60] -1.349e+01  1.389e-06  1.539e+03 -0.009 0.993008
## 
## Likelihood ratio test=10.42  on 2 df, p=0.005452
## n= 686, number of events= 299
obs_n = c(290, 9,0)
exp_n = c(296.103,2.585, 0.313)
w_n = c(-1,0,1)
u_n = sum(w_n*(obs_n-exp_n ))
v_n = sum(w_n^2*exp_n)- ((sum(w_n*exp_n))^2/(sum(exp_n)))
x_n = u_n^2/v_n
x_n
## [1] 8.816292
pchisq(x_n, df=1, lower.tail=F)
## [1] 0.002985527

In this case, we also use trend test since we want to compare the survival curves of more than three ordered groups of number of axillary lymph nodes with metastases which can be arrange or ordered, with that the magnitude of the differences is relevant. Hence, there will be three group arrangement for the axillary lymph nodes with metastases.

The results show that p-value of 0.002985527 < \(a=0.05\) , thus null hypotheses will be rejected which means that the survival times for different groups are not the same. Therefore, we can conclude that at least one survival times for different groups of axillary lymph nodes with metastases are not equal.