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)
########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)
 
Best regards, 
Hong
                                          
        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to