[R] How to access results of survival analysis
Xiaochun Li
xiaochun at jimmy.harvard.edu
Fri May 5 16:40:33 CEST 2006
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