You are here: Vanderbilt Biostatistics Wiki>Main Web>Seminars>RClinic>MultipleKMCurves (14 Nov 2006, TheresaScott)EditAttach

`Rtestdata.sav`

SPSS data set.
library(Hmisc) library(Design) test <- spss.get("Rtestdata.sav", lowernames=TRUE) contents(test)

subset(test, event != died)

`follup2d`

values of > 730 with 730.
test <- upData(test, trunc.folup2d = ifelse(folup2d > 730, 730, folup2d))

# (1) Died within 2 years f.win2y <- survfit(with(test, Surv(trunc.folup2d, event=="Yes"))) # (2) Died after 2 years f.after2y <- survfit(with(test, Surv(trunc.folup2d, died=="Yes")))

# (1) Plot using the plot.survfit() function (survival package) plot(f.win2y, xmax=730, ymin=0.5, xlab="Time in days", ylab="Survival function") par(new=TRUE) plot(f.after2y, xmax=730, ymin=0.5, xlab="", ylab="", col="red") par(col="black") box() legend(x=25, y=0.5, legend=c("Assuming died within 2 years", "Assuming died after 2 years"), col=c("black", "red"), lty=1, xjust=0, yjust=0) # Can also add the f.after2y Survival curve and CIs # using the lines() function, but it does not show # censoring tick marks plot(f.win2y, xmax=730, ymin=0.5, xlab="Time in days", ylab="Survival function") # NOTE: lines function does not properly _step_ down # the survival curve. Will want to use the stepfun # function instead. with(f.after2y, lines(time, lower, lty=2, col="red")) lines(f.after2y, col="red", mark.time=TRUE) with(f.after2y, lines(time, lower, lty=2, col="red")) # (2) Plot using survplot --> survplot.Design (Design package) # Doesn't show censoring survplot(f.win2y, conf="bands", time.inc=60, xlim=c(0, 730), ylim=c(0.5, 1.0)) survplot(f.after2y, add=TRUE, col="red", conf="bands", time.inc=60, xlim=c(0, 730), ylim=c(0.5, 1.0)) box() legend(x=25, y=0.5, legend=c("Assuming died within 2 years", "Assuming died after 2 years"), col=c("black", "red"), lty=1, xjust=0, yjust=0)

Edit | Attach | Print version | History: r2 < r1 | Backlinks | View wiki text | Edit wiki text | More topic actions

Topic revision: r2 - 14 Nov 2006, TheresaScott

Copyright © 2013-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.

Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback

Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback