2
$\begingroup$

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
$\endgroup$
10
  • 1
    $\begingroup$ Here you use the left-continuous version of the Kaplan-Meier estimate (option right=FALSE), so the result is correct. $\endgroup$ Commented Apr 19, 2012 at 7:14
  • 1
    $\begingroup$ Try this: surv <- approxfun(km$time, km$surv, method="constant", yleft=1) $\endgroup$ Commented Apr 19, 2012 at 8:19
  • 1
    $\begingroup$ It looks to work with 'sort(time)'. This is a bit wierd... but many thanks! $\endgroup$
    – user7064
    Commented Apr 19, 2012 at 9:02
  • 1
    $\begingroup$ In passing do not use "time" as a variable name ! This is the name of a R function and this can be dangerous ! $\endgroup$ Commented Apr 19, 2012 at 9:05
  • 1
    $\begingroup$ Ok... thanks. By the way, the solution with "sort(time)" may fail in case of ties... $\endgroup$
    – user7064
    Commented Apr 19, 2012 at 9:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.