Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

Based on a sample of $n$ survival times, I would like to estimate the probability of surviving time $t$, for some specific $t$, using the Kaplan-Meier estimator. Is it possible to do this in R? Please, note that $t$ is not necessarily an event time.

share|improve this question
Of course: see the survfit() function of the survival package [type help(package="survival")] – Stéphane Laurent Apr 11 '12 at 10:06
@Stephane Laurent: The surfit() function outputs the estimated survival at event times. But I'd like to have an automatic procedure to compute that survival at any time t. Thanks... – user7064 Apr 11 '12 at 10:16
Then use approxfun() – Stéphane Laurent Apr 11 '12 at 13:28
can I have an example? – user7064 Apr 11 '12 at 13:29

1 Answer

up vote 6 down vote accepted

You can use the output of the survfit function from the survival package and give that to stepfun.

km <- survfit(Surv(time, status)~1, data=veteran)
survest <- stepfun(km$time, c(1, km$surv))

Now survest is a function that can be evaluated at any time.

> survest(0:100)
  [1] 1.0000000 0.9854015 0.9781022 0.9708029 0.9635036 0.9635036 0.9635036
  [8] 0.9416058 0.9124088 0.9124088 0.8978102 0.8905109 0.8759124 0.8613139
 [15] 0.8613139 0.8467153 0.8394161 0.8394161 0.8175182 0.8029197 0.7883212
 [22] 0.7737226 0.7664234 0.7664234 0.7518248 0.7299270 0.7299270 0.7225540
 [29] 0.7225540 0.7151810 0.7004350 0.6856890 0.6856890 0.6783160 0.6783160
 [36] 0.6709430 0.6635700 0.6635700 0.6635700 0.6635700 0.6635700 0.6635700
 [43] 0.6561970 0.6488240 0.6414510 0.6340780 0.6340780 0.6340780 0.6267050
 [50] 0.6193320 0.6193320 0.5972130 0.5750940 0.5677210 0.5529750 0.5529750
 [57] 0.5456020 0.5456020 0.5456020 0.5382290 0.5382290 0.5308560 0.5308560
 [64] 0.5234830 0.5234830 0.5234830 0.5234830 0.5234830 0.5234830 0.5234830
 [71] 0.5234830 0.5234830 0.5161100 0.5087370 0.5087370 0.5087370 0.5087370
 [78] 0.5087370 0.5087370 0.5087370 0.4939910 0.4939910 0.4866180 0.4866180
 [85] 0.4791316 0.4791316 0.4791316 0.4716451 0.4716451 0.4716451 0.4640380
 [92] 0.4640380 0.4564308 0.4564308 0.4564308 0.4412164 0.4412164 0.4412164
 [99] 0.4412164 0.4257351 0.4179945
share|improve this answer
Thank you very much! – user7064 Apr 11 '12 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.