Zheng Lu
2011-Oct-29 03:30 UTC
[R] How to plot survival data from multiple trials (simulations)?
Dear all: Could anyone please provide some R codes to plot the below survival data to compare two groups (0 vs 1) after 2 simulations (TRL)? need 95% prediction interval on the plot from these 2 trials. I would like to simulate 1000 trials later. Thanks a lot for your great help and consideration! yan TRL ID ECOG BASE PTR8 GROUP POP ST ind 1 1 1 1 2.2636717 0.255634126 1 1 99.4 F 3 1 2 1 24.7719223 0.756458142 0 1 8.1 T 5 1 3 0 4.7685832 0.908777937 1 0 2.6 T 7 1 4 0 2.5934492 -0.231564522 1 1 7.4 T 9 1 5 0 4.7309141 -2.455991696 0 1 0.4 T 11 1 6 1 3.5904766 -0.459694803 1 1 13.1 T 13 1 7 1 4.8592495 0.983131140 1 1 17.8 T 15 1 8 1 3.1308760 -1.136462783 0 0 10.6 T 17 1 9 1 5.8127637 -0.131647588 0 1 1.2 T 19 1 10 0 4.0875668 -3.567509428 0 1 0.4 T 21 1 11 1 14.7112528 0.900416367 1 1 15.2 T 23 1 12 0 6.7290298 -0.140283251 0 0 8.5 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 25 1 13 0 6.6118789 -0.095603854 0 1 13.8 T 27 1 14 1 1.1191479 0.735691765 1 1 60.5 F 29 1 15 0 11.9169275 0.796172293 0 0 40.1 F 31 1 16 1 6.7940011 0.845746271 1 1 68.1 F 33 1 17 0 4.7380330 0.582527179 1 1 11.7 T 35 1 18 0 12.0571049 0.165637187 0 0 25.0 T 37 1 19 1 3.1922217 0.891862148 1 1 34.0 T 39 1 20 0 10.6253830 -0.747701704 0 1 7.8 T 41 1 21 0 2.0178336 -2.732716143 0 1 0.8 T 43 1 22 1 13.8066137 0.706372607 0 1 58.2 F 45 1 23 1 11.8844261 0.842735359 1 1 13.9 T 47 1 24 1 3.9546421 0.193353044 0 1 2.7 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 49 1 25 0 27.0913396 0.970400135 1 1 19.1 T 51 1 26 1 12.0249672 0.886403017 1 1 27.1 T 53 1 27 1 5.9453281 0.964694968 1 1 21.2 T 55 1 28 0 6.8084911 -1.333850454 1 0 4.1 T 57 1 29 1 8.3642227 -0.024960757 0 1 4.4 T 59 1 30 0 26.6382483 0.714020234 0 0 3.9 T 61 1 31 1 13.1107410 0.372041597 0 1 26.2 T 63 1 32 0 4.2271255 0.056569282 1 1 14.3 T 65 1 33 0 17.7269456 0.252550311 0 0 11.2 T 67 1 34 1 3.6215522 -0.282323084 0 0 0.3 T 69 1 35 1 19.3787770 0.349288143 0 1 5.2 T 71 1 36 0 8.9546567 0.945492048 1 1 15.2 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 73 1 37 0 2.7796959 -3.119155682 0 0 12.3 T 75 1 38 0 9.4029912 -0.793046460 0 1 1.2 T 77 1 39 1 7.8146429 0.888593758 1 1 8.0 T 79 1 40 0 9.6419102 0.525301532 1 1 22.4 T 81 1 41 1 3.3174969 0.915870306 1 1 24.7 T 83 1 42 1 12.4030358 0.661856980 1 1 16.4 T 85 1 43 1 24.2982862 0.710967270 0 1 5.5 T 87 1 44 0 10.4332028 0.940833126 1 0 2.9 T 89 1 45 0 4.7520799 0.897518558 1 1 32.6 T 91 1 46 0 2.7028663 -3.484128492 0 1 0.2 T 93 1 47 1 2.7572158 0.890976979 1 0 30.9 T 95 1 48 0 7.2240161 -0.377073350 0 0 3.7 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 97 1 49 0 20.6156368 0.500864314 0 1 12.2 T 99 1 50 1 12.8547093 0.982784519 1 1 54.4 F 2 2 1 1 3.0862631 0.931988949 1 1 199.2 F 4 2 2 1 18.6633707 0.540651036 0 1 8.1 T 6 2 3 0 5.5728260 -1.851336117 1 0 3.0 T 8 2 4 0 4.0740408 0.021119280 1 1 10.1 T 10 2 5 0 14.2396242 0.465013972 0 1 6.6 T 12 2 6 1 37.5234448 0.986992132 1 1 30.5 T 14 2 7 1 11.2925748 0.922905093 1 1 14.0 T 16 2 8 1 15.2298842 0.459418082 0 0 12.6 T 18 2 9 1 5.3266590 -1.487487920 0 1 0.3 T 20 2 10 0 11.7956270 0.606294774 0 1 26.9 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 22 2 11 1 26.0051377 0.823996317 1 1 8.6 T 24 2 12 0 4.7851855 -1.635216564 0 0 10.7 T 26 2 13 0 5.4896572 -1.085740446 0 1 3.8 T 28 2 14 1 15.0284557 0.981428564 1 1 56.1 F 30 2 15 0 15.3001584 -0.101949376 0 0 36.7 T 32 2 16 1 4.1838899 -0.002416447 1 1 26.0 T 34 2 17 0 1.9213881 0.678721863 1 1 15.5 T 36 2 18 0 22.0870166 0.682030393 0 0 18.8 T 38 2 19 1 7.8815644 0.938210236 1 1 25.9 T 40 2 20 0 6.8308086 -0.774314088 0 1 8.5 T 42 2 21 0 6.0056206 -0.656448295 0 1 5.4 T 44 2 22 1 11.9301049 0.137476151 0 1 32.2 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 46 2 23 1 4.4453597 0.932378925 1 1 18.3 T 48 2 24 1 7.0352655 0.142463064 0 1 2.4 T 50 2 25 0 22.1603315 0.990013687 1 1 23.5 T 52 2 26 1 1.7582992 0.041687569 1 1 13.6 T 54 2 27 1 4.0864310 0.893550143 1 1 18.7 T 56 2 28 0 3.7564158 0.149721394 1 0 3.1 T 58 2 29 1 23.7880592 0.312680371 0 1 4.0 T 60 2 30 0 7.3082204 0.084729300 0 0 3.4 T 62 2 31 1 29.8669157 0.779756301 0 1 24.3 T 64 2 32 0 6.7967624 0.228897567 1 1 15.8 T 66 2 33 0 9.0048160 -1.073334969 0 0 9.5 T 68 2 34 1 9.3920052 0.183028557 0 0 0.3 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 70 2 35 1 17.0794700 0.575865059 0 1 6.7 T 72 2 36 0 5.8638675 0.986021171 1 1 18.2 T 74 2 37 0 12.7073727 0.808851125 0 0 11.6 T 76 2 38 0 6.6391834 -0.515246589 0 1 1.5 T 78 2 39 1 4.0731162 0.640324530 1 1 6.9 T 80 2 40 0 8.1501724 0.963706289 1 1 37.9 T 82 2 41 1 7.1095450 0.852592536 1 1 19.9 T 84 2 42 1 6.3169479 0.686874101 1 1 23.2 T 86 2 43 1 12.8719503 -0.442671821 0 1 2.5 T 88 2 44 0 19.2469239 0.982064666 1 0 3.3 T 90 2 45 0 6.7743672 0.724107074 1 1 24.1 T 92 2 46 0 7.9332652 0.050580084 0 1 5.9 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 94 2 47 1 0.6997334 -0.146007844 1 0 23.7 T 96 2 48 0 14.6486847 0.723251604 0 0 4.5 T 98 2 49 0 4.1576131 0.232732832 0 1 15.6 T 100 2 50 1 7.2583626 0.811803286 1 1 49.0 F [[alternative HTML version deleted]]
Lancaster, Robert (Orbitz)
2011-Oct-29 16:49 UTC
[R] How to plot survival data from multiple trials (simulations)?
I'm assuming you want to plot the Kaplan-Meier curves. First, load your data into a data.frame, e.g. surv_data It looks like ST is your survival time and ind is your event indicator. The following code should get you started: # create your survival object: mySurv = Surv(surv_data$ST,surv_data$ind) # use survfit, which will generate KM curves: survFit = survfit(mySurv~surv_data$GROUP) # plot your curves. plot(survFit,conf.int=TRUE,xlab="time",ylab="survival pct") -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Zheng Lu Sent: Friday, October 28, 2011 10:30 PM To: r-help at r-project.org Subject: [R] How to plot survival data from multiple trials (simulations)? Dear all: Could anyone please provide some R codes to plot the below survival data to compare two groups (0 vs 1) after 2 simulations (TRL)? need 95% prediction interval on the plot from these 2 trials. I would like to simulate 1000 trials later. Thanks a lot for your great help and consideration! yan TRL ID ECOG BASE PTR8 GROUP POP ST ind 1 1 1 1 2.2636717 0.255634126 1 1 99.4 F 3 1 2 1 24.7719223 0.756458142 0 1 8.1 T 5 1 3 0 4.7685832 0.908777937 1 0 2.6 T 7 1 4 0 2.5934492 -0.231564522 1 1 7.4 T 9 1 5 0 4.7309141 -2.455991696 0 1 0.4 T 11 1 6 1 3.5904766 -0.459694803 1 1 13.1 T 13 1 7 1 4.8592495 0.983131140 1 1 17.8 T 15 1 8 1 3.1308760 -1.136462783 0 0 10.6 T 17 1 9 1 5.8127637 -0.131647588 0 1 1.2 T 19 1 10 0 4.0875668 -3.567509428 0 1 0.4 T 21 1 11 1 14.7112528 0.900416367 1 1 15.2 T 23 1 12 0 6.7290298 -0.140283251 0 0 8.5 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 25 1 13 0 6.6118789 -0.095603854 0 1 13.8 T 27 1 14 1 1.1191479 0.735691765 1 1 60.5 F 29 1 15 0 11.9169275 0.796172293 0 0 40.1 F 31 1 16 1 6.7940011 0.845746271 1 1 68.1 F 33 1 17 0 4.7380330 0.582527179 1 1 11.7 T 35 1 18 0 12.0571049 0.165637187 0 0 25.0 T 37 1 19 1 3.1922217 0.891862148 1 1 34.0 T 39 1 20 0 10.6253830 -0.747701704 0 1 7.8 T 41 1 21 0 2.0178336 -2.732716143 0 1 0.8 T 43 1 22 1 13.8066137 0.706372607 0 1 58.2 F 45 1 23 1 11.8844261 0.842735359 1 1 13.9 T 47 1 24 1 3.9546421 0.193353044 0 1 2.7 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 49 1 25 0 27.0913396 0.970400135 1 1 19.1 T 51 1 26 1 12.0249672 0.886403017 1 1 27.1 T 53 1 27 1 5.9453281 0.964694968 1 1 21.2 T 55 1 28 0 6.8084911 -1.333850454 1 0 4.1 T 57 1 29 1 8.3642227 -0.024960757 0 1 4.4 T 59 1 30 0 26.6382483 0.714020234 0 0 3.9 T 61 1 31 1 13.1107410 0.372041597 0 1 26.2 T 63 1 32 0 4.2271255 0.056569282 1 1 14.3 T 65 1 33 0 17.7269456 0.252550311 0 0 11.2 T 67 1 34 1 3.6215522 -0.282323084 0 0 0.3 T 69 1 35 1 19.3787770 0.349288143 0 1 5.2 T 71 1 36 0 8.9546567 0.945492048 1 1 15.2 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 73 1 37 0 2.7796959 -3.119155682 0 0 12.3 T 75 1 38 0 9.4029912 -0.793046460 0 1 1.2 T 77 1 39 1 7.8146429 0.888593758 1 1 8.0 T 79 1 40 0 9.6419102 0.525301532 1 1 22.4 T 81 1 41 1 3.3174969 0.915870306 1 1 24.7 T 83 1 42 1 12.4030358 0.661856980 1 1 16.4 T 85 1 43 1 24.2982862 0.710967270 0 1 5.5 T 87 1 44 0 10.4332028 0.940833126 1 0 2.9 T 89 1 45 0 4.7520799 0.897518558 1 1 32.6 T 91 1 46 0 2.7028663 -3.484128492 0 1 0.2 T 93 1 47 1 2.7572158 0.890976979 1 0 30.9 T 95 1 48 0 7.2240161 -0.377073350 0 0 3.7 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 97 1 49 0 20.6156368 0.500864314 0 1 12.2 T 99 1 50 1 12.8547093 0.982784519 1 1 54.4 F 2 2 1 1 3.0862631 0.931988949 1 1 199.2 F 4 2 2 1 18.6633707 0.540651036 0 1 8.1 T 6 2 3 0 5.5728260 -1.851336117 1 0 3.0 T 8 2 4 0 4.0740408 0.021119280 1 1 10.1 T 10 2 5 0 14.2396242 0.465013972 0 1 6.6 T 12 2 6 1 37.5234448 0.986992132 1 1 30.5 T 14 2 7 1 11.2925748 0.922905093 1 1 14.0 T 16 2 8 1 15.2298842 0.459418082 0 0 12.6 T 18 2 9 1 5.3266590 -1.487487920 0 1 0.3 T 20 2 10 0 11.7956270 0.606294774 0 1 26.9 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 22 2 11 1 26.0051377 0.823996317 1 1 8.6 T 24 2 12 0 4.7851855 -1.635216564 0 0 10.7 T 26 2 13 0 5.4896572 -1.085740446 0 1 3.8 T 28 2 14 1 15.0284557 0.981428564 1 1 56.1 F 30 2 15 0 15.3001584 -0.101949376 0 0 36.7 T 32 2 16 1 4.1838899 -0.002416447 1 1 26.0 T 34 2 17 0 1.9213881 0.678721863 1 1 15.5 T 36 2 18 0 22.0870166 0.682030393 0 0 18.8 T 38 2 19 1 7.8815644 0.938210236 1 1 25.9 T 40 2 20 0 6.8308086 -0.774314088 0 1 8.5 T 42 2 21 0 6.0056206 -0.656448295 0 1 5.4 T 44 2 22 1 11.9301049 0.137476151 0 1 32.2 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 46 2 23 1 4.4453597 0.932378925 1 1 18.3 T 48 2 24 1 7.0352655 0.142463064 0 1 2.4 T 50 2 25 0 22.1603315 0.990013687 1 1 23.5 T 52 2 26 1 1.7582992 0.041687569 1 1 13.6 T 54 2 27 1 4.0864310 0.893550143 1 1 18.7 T 56 2 28 0 3.7564158 0.149721394 1 0 3.1 T 58 2 29 1 23.7880592 0.312680371 0 1 4.0 T 60 2 30 0 7.3082204 0.084729300 0 0 3.4 T 62 2 31 1 29.8669157 0.779756301 0 1 24.3 T 64 2 32 0 6.7967624 0.228897567 1 1 15.8 T 66 2 33 0 9.0048160 -1.073334969 0 0 9.5 T 68 2 34 1 9.3920052 0.183028557 0 0 0.3 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 70 2 35 1 17.0794700 0.575865059 0 1 6.7 T 72 2 36 0 5.8638675 0.986021171 1 1 18.2 T 74 2 37 0 12.7073727 0.808851125 0 0 11.6 T 76 2 38 0 6.6391834 -0.515246589 0 1 1.5 T 78 2 39 1 4.0731162 0.640324530 1 1 6.9 T 80 2 40 0 8.1501724 0.963706289 1 1 37.9 T 82 2 41 1 7.1095450 0.852592536 1 1 19.9 T 84 2 42 1 6.3169479 0.686874101 1 1 23.2 T 86 2 43 1 12.8719503 -0.442671821 0 1 2.5 T 88 2 44 0 19.2469239 0.982064666 1 0 3.3 T 90 2 45 0 6.7743672 0.724107074 1 1 24.1 T 92 2 46 0 7.9332652 0.050580084 0 1 5.9 T TRL ID ECOG BASE PTR8 GROUP POP ST ind 94 2 47 1 0.6997334 -0.146007844 1 0 23.7 T 96 2 48 0 14.6486847 0.723251604 0 0 4.5 T 98 2 49 0 4.1576131 0.232732832 0 1 15.6 T 100 2 50 1 7.2583626 0.811803286 1 1 49.0 F [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.