# Estimating a survival probability in R (2)

Following Brian Diggs's answer, I have tried to estimate some survival probability in R. However, the result is wrong (1 instead of 0.9) and I do not understand what is going on... Can you explain me?

> time
[1] 1.38103330 2.14191380 1.47271212 0.02703924 0.34921793 3.01005383 1.01132532 0.09546903 0.44729971 1.12909544
> event
[1] 1 1 1 1 1 1 1 1 1 1
> km <- survfit(Surv(time, event) ~ 1)
> surv <- stepfun(km$time, c(1, km$surv), right=FALSE, f=0)
> surv(min(time))
[1] 1
• Here you use the left-continuous version of the Kaplan-Meier estimate (option right=FALSE), so the result is correct. Commented Apr 19, 2012 at 7:14
• Try this: surv <- approxfun(km$time, km$surv, method="constant", yleft=1) Commented Apr 19, 2012 at 8:19
• It looks to work with 'sort(time)'. This is a bit wierd... but many thanks! Commented Apr 19, 2012 at 9:02
• In passing do not use "time" as a variable name ! This is the name of a R function and this can be dangerous ! Commented Apr 19, 2012 at 9:05
• Ok... thanks. By the way, the solution with "sort(time)" may fail in case of ties... Commented Apr 19, 2012 at 9:08