On Dec 3, 2012, at 1:19 PM, Tian3507 wrote:
Dear all,
I am trying to plot KM curves with confidence bands with function
survplot under package rms.
However, the following codes do not seem to work. The KM curves are
produced, but the confidence bands are not there.
Any insights? Thanks in advance.
library(rms)
########data generation############
n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
label(age) <- "Age"
sex <- factor(sample(c('male','female'), n, TRUE))
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50)+.8*(sex=='female'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'
e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- 'Year'
dd <- datadist(age, sex)
options(datadist='dd')
S <- Surv(dt,e)
tte<-data.frame(dt,e,age,sex)
############male group KM curve with bands#############
f <- survfit(Surv(dt,e)~1, data=tte,subset=sex=='male')
survplot(f,conf="bands", conf.int=0.95)
Reading the "manual" would seem to be the first step:
" conf.int
..... This argument is ignored for fits from survfit, which must have
previously specified confidence interval specifications."
Although I then noted that your code (and the obvious shift of
conf.int as an argument to survfit) _both_ created the same confidence
bands on my machine, so we appear to have different versions (or OS or
machines) running. Reading the help page for survfit leaves me a bit
puzzled since the default for conf.int is 0.95, so I am unable to
explain why you did not get the confidence bands.
OS= Mac 10.6.8; R= 2.15.2; rms_3.5-0 Hmisc_3.9-3
--
David.
########notice no confidence band created#############
############female group KM curve with bands#############
g <- survfit(Surv(dt,e)~1, data=tte,subset=sex!='male')
survplot(g,conf="bands", conf.int=0.95,col=3, add=T)
--
David Winsemius, MD
Alameda, CA, USA
______________________________________________
R-help@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.