[R] How to access results of survival analysis

Heinz Tuechler tuechler at gmx.at
Sun May 7 12:16:23 CEST 2006


Hello Xiaochun Li!

Thank you for submitting the function. At the time I had that problem I
solved it in a somewhat different way.
I 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)

So print.survfit returned the results. Of course, Your method has the
advantage to work as long as the output structure of print.survfit does not
change. At the end I would prefer the original function to be changed and
when I find the time I will submit a worked proposal to Thomas Lumley, the
maintainer of the survival package. In that way it would be available also
in future versions of survival.

Greetings

Heinz


At 10:40 05.05.2006 -0400, you wrote:
>Hi List,
>
>A friend of mine recently asked the same question as Heinz Tüchler.  Since
>I've already written the code I'd like to share with the list.
>
># x is an object returned by "survfit";
># "smed" returns a matrix of 5 columns of
># n, events, median, 0.95LCL, 0.95UCL.
># The matrix returned has rownames as the
># group labels (eg., treatment arms) if any.
>
>smed <- function(x) {
>        ox <- capture.output(print(x))
>        n <- length(ox)
>        tmp <- t(sapply(ox[4:n],          
>                function(l) strsplit(l, split=' +')[[1]]))
>        nres <- strsplit(ox[3],split=' +')[[1]][2:6]
>        res <- matrix(as.numeric(tmp[,2:6]), ncol=5,
>                dimnames=list(tmp[,1], nres))
>        res
>}
>
>
># example:
>
>library(survival)
>
>fit1 <- survfit(Surv(time, status) ~ 1, data=aml)   
>sf1 <- smed(fit1)
>sf1
>
>
>fit <- survfit(Surv(time, status) ~ x, data=aml)
>sf <- smed(fit)
>sf
>
>-- 
>Xiaochun Li, Ph.D.
>Research Scientist
>Department of Biostatistics and Computational Biology
>Dana Farber Cancer Institute
>Harvard School of Public Health
>
>M1B25
>(617) 632 3602
>
>




More information about the R-help mailing list