[R] How to access results of survival analysis

From: Xiaochun Li <xiaochun_at_jimmy.harvard.edu>
Date: Sat 06 May 2006 - 00:40:33 EST

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))


# example:


fit1 <- survfit(Surv(time, status) ~ 1, data=aml) sf1 <- smed(fit1)

fit <- survfit(Surv(time, status) ~ x, data=aml) sf <- smed(fit)

Xiaochun Li, Ph.D.
Research Scientist
Department of Biostatistics and Computational Biology
Dana Farber Cancer Institute
Harvard School of Public Health

(617) 632 3602

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat May 06 00:51:05 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 07 May 2006 - 20:10:00 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.