# 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. –  Stéphane Laurent Apr 19 '12 at 7:14
@Stéphane Laurent: But according to the 'help' page, "For the default, right = FALSE, f = 0, fn is a cadlag function, i.e., continuous at right, limit (‘the point’) at left.". –  user7064 Apr 19 '12 at 7:20
Strange - you could also try approxfun() with option method="constant" –  Stéphane Laurent Apr 19 '12 at 7:35
Can I have an example with approxfun() ? –  user7064 Apr 19 '12 at 8:09
Try this: surv <- approxfun(km$time, km$surv, method="constant", yleft=1) –  Stéphane Laurent Apr 19 '12 at 8:19