Hello, it seems that the main results of survival analysis with package survival are shown only as side effects of the print method. If I compute e.g. a Kaplan-Meier estimate by> km.survdur<-survfit(s.survdur)then I can simply print the results by> km.survdurCall: survfit(formula = s.survdur) n events median 0.95LCL 0.95UCL 100.0 58.0 46.8 41.0 79.3 Is there a simple method to access these results, e.g. if I want to print only the median with the confidence limits? Regarding the results of a Cox-PH-model I face the same situation. The printed results are:> cx.survdur.ipss_mds.sexCall: coxph(formula = s.survdur ~ x1 + x2, method = "efron") coef exp(coef) se(coef) z p x1 0.6424 1.90 0.206 3.123 0.0018 x2.L 0.0616 1.06 0.263 0.234 0.8100 Likelihood ratio test=9.56 on 2 df, p=0.0084 n=58 (42 observations deleted due to missing) Is there a simple method to copy e.g. the coefficients and p-values in a new object? I am working with: R : Copyright 2004, The R Foundation for Statistical Computing Version 2.0.1 (2004-11-15), ISBN 3-900051-07-0 Survival package version: survival_2.16 Operating System: Windows 98SE Thanks, Heinz T?chler
Heinz Tuechler wrote:> Hello, > > it seems that the main results of survival analysis with package survival > are shown only as side effects of the print method. > > If I compute e.g. a Kaplan-Meier estimate by > >>km.survdur<-survfit(s.survdur) > > then I can simply print the results by > >>km.survdur > > Call: survfit(formula = s.survdur) > > n events median 0.95LCL 0.95UCL > 100.0 58.0 46.8 41.0 79.3 > > Is there a simple method to access these results, e.g. if I want to print > only the median with the confidence limits? > Regarding the results of a Cox-PH-model I face the same situation. The > printed results are: > >>cx.survdur.ipss_mds.sex > > Call: > coxph(formula = s.survdur ~ x1 + x2, method = "efron") > > coef exp(coef) se(coef) z p > x1 0.6424 1.90 0.206 3.123 0.0018 > x2.L 0.0616 1.06 0.263 0.234 0.8100 > > Likelihood ratio test=9.56 on 2 df, p=0.0084 n=58 (42 observations > deleted due to missing) > > Is there a simple method to copy e.g. the coefficients and p-values in a > new object? > > I am working with: > R : Copyright 2004, The R Foundation for Statistical Computing > Version 2.0.1 (2004-11-15), ISBN 3-900051-07-0 > Survival package version: survival_2.16 > Operating System: Windows 98SE > > Thanks, > Heinz T?chler > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlNo, the print methods do not return those values. But you can copy code for calculation of the required values from those print methods into your own functions... Uwe Ligges
Hello Ales, thank you for your hint regarding names(summary(fit)). Summary(fit) is a list containig all important results of the Cox-model. So it helps a lot! Regarding the results of a Kaplan-Meier estimate summary does not help, because it does not contain the main results. Thanks again, Heinz T?chler ps. If I understood it right, you answered only to me and not to the list. So I assumed that you prefer not to put your answer on the list and therefore I answer to you off-list. At 09:24 05.02.2005 +0100, Ales Ziberna wrote:>Hi! > >I don't now how to reach the median directly. However I can help you whit >cox-PH coefficients. > >if fit is the resoult of the coxph, then > >fit$coefficients should give you the coefficients. To see whatother things >you can acces in similar way, see >names(fit) >or >names(summary(fit)). > >I hope this helps at least a little! > >Ales Ziberna > > >----- Original Message ----- >From: "Heinz Tuechler" <tuechler at gmx.at> >To: <r-help at stat.math.ethz.ch> >Sent: Friday, February 04, 2005 11:17 PM >Subject: [R] How to access results of survival analysis > > >Hello, > >it seems that the main results of survival analysis with package survival >are shown only as side effects of the print method. > >If I compute e.g. a Kaplan-Meier estimate by >> km.survdur<-survfit(s.survdur) >then I can simply print the results by >> km.survdur >Call: survfit(formula = s.survdur) > > n events median 0.95LCL 0.95UCL > 100.0 58.0 46.8 41.0 79.3 > >Is there a simple method to access these results, e.g. if I want to print >only the median with the confidence limits? >Regarding the results of a Cox-PH-model I face the same situation. The >printed results are: >> cx.survdur.ipss_mds.sex >Call: >coxph(formula = s.survdur ~ x1 + x2, method = "efron") > > coef exp(coef) se(coef) z p >x1 0.6424 1.90 0.206 3.123 0.0018 >x2.L 0.0616 1.06 0.263 0.234 0.8100 > >Likelihood ratio test=9.56 on 2 df, p=0.0084 n=58 (42 observations >deleted due to missing) > >Is there a simple method to copy e.g. the coefficients and p-values in a >new object? > >I am working with: >R : Copyright 2004, The R Foundation for Statistical Computing >Version 2.0.1 (2004-11-15), ISBN 3-900051-07-0 >Survival package version: survival_2.16 >Operating System: Windows 98SE > >Thanks, >Heinz T?chler > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! >http://www.R-project.org/posting-guide.html > > >
At 15:19 05.02.2005 +0100, Uwe Ligges wrote:>Heinz Tuechler wrote: >> Hello, >> >> it seems that the main results of survival analysis with package survival >> are shown only as side effects of the print method. >> >> If I compute e.g. a Kaplan-Meier estimate by >> >>>km.survdur<-survfit(s.survdur) >> >> then I can simply print the results by >> >>>km.survdur >> >> Call: survfit(formula = s.survdur) >> >> n events median 0.95LCL 0.95UCL >> 100.0 58.0 46.8 41.0 79.3 >> >> Is there a simple method to access these results, e.g. if I want to print >> only the median with the confidence limits?...> >No, the print methods do not return those values. >But you can copy code for calculation of the required values from those >print methods into your own functions... > >Uwe Ligges > >Thank you for your answer. I assume, you suggest to use capture.output(print(...)). Without your response I would have believed that I had missed an important possibility of R. Regarding the Cox-Model Ales Ziberna gave me a useful hint to use summary() which returns a list. Thanks to both of you, Heinz T?chler
Heinz Tuechler wrote:> At 15:19 05.02.2005 +0100, Uwe Ligges wrote: > >>Heinz Tuechler wrote: >> >>>Hello, >>> >>>it seems that the main results of survival analysis with package survival >>>are shown only as side effects of the print method. >>> >>>If I compute e.g. a Kaplan-Meier estimate by >>> >>> >>>>km.survdur<-survfit(s.survdur) >>> >>>then I can simply print the results by >>> >>> >>>>km.survdur >>> >>>Call: survfit(formula = s.survdur) >>> >>> n events median 0.95LCL 0.95UCL >>> 100.0 58.0 46.8 41.0 79.3 >>> >>>Is there a simple method to access these results, e.g. if I want to print >>>only the median with the confidence limits? > > > ... > >>No, the print methods do not return those values. >>But you can copy code for calculation of the required values from those >>print methods into your own functions... >> >>Uwe Ligges >> >> > > Thank you for your answer. I assume, you suggest to use > capture.output(print(...)).No, I suggested to copy the code from survival:::print.survfit and Co. that calculates the values you are looking for... Uwe > Without your response I would have believed> that I had missed an important possibility of R. > > Regarding the Cox-Model Ales Ziberna gave me a useful hint to use summary() > which returns a list. > > Thanks to both of you, > > Heinz T?chler
To sum up: Starting from the question, how to access the results of survival analysis Uwe Liggens suggested to ...copy code for calculation of the required values from those print methods into your own functions... Since I am new to R I choose the easiest way I knew and changed a few lines in the print.survfit method. I introduced a parameter "ret.res=FALSE" set to false to preserve the normal behaviour of print. The second last line "invisible(x)" I changed to: if (ret.res) invisible(list(x,x1)) else invisible(x) Finally I source the changed function. Of course this is only a temporary workaround, but it seems to work. Thanks, Heinz T?chler At 19:09 05.02.2005 +0100, Uwe Ligges wrote:>Heinz Tuechler wrote: > >> At 15:19 05.02.2005 +0100, Uwe Ligges wrote: >> >>>Heinz Tuechler wrote: >>> >>>>Hello, >>>> >>>>it seems that the main results of survival analysis with package survival >>>>are shown only as side effects of the print method. >>>> >>>>If I compute e.g. a Kaplan-Meier estimate by >>>> >>>> >>>>>km.survdur<-survfit(s.survdur) >>>> >>>>then I can simply print the results by >>>> >>>> >>>>>km.survdur >>>> >>>>Call: survfit(formula = s.survdur) >>>> >>>> n events median 0.95LCL 0.95UCL >>>> 100.0 58.0 46.8 41.0 79.3 >>>> >>>>Is there a simple method to access these results, e.g. if I want to print >>>>only the median with the confidence limits? >> >> >> ... >> >>>No, the print methods do not return those values. >>>But you can copy code for calculation of the required values from those >>>print methods into your own functions... >>> >>>Uwe Ligges >>> >>> >> >> Thank you for your answer. I assume, you suggest to use >> capture.output(print(...)). > >No, I suggested to copy the code from survival:::print.survfit and Co. >that calculates the values you are looking for... > >Uwe > > > Without your response I would have believed >> that I had missed an important possibility of R. >> >> Regarding the Cox-Model Ales Ziberna gave me a useful hint to use summary() >> which returns a list. >> >> Thanks to both of you, >> >> Heinz T?chler > >