Andreas Wittmann

2010-Dec-10 19:07 UTC

### [R] survival package - calculating probability to survive a given time

Dear R users, i try to calculate the probabilty to survive a given time by using the estimated survival curve by kaplan meier. What is the right way to do that? as far as is see i cannot use the predict-methods from the survival package? library(survival) set.seed(1) time <- cumsum(rexp(1000)/10) status <- rbinom(1000, 1, 0.5) ## kaplan meier estimates fit <- survfit(Surv(time, status) ~ 1) s <- summary(fit) ## 1. possibility to get the probability for surviving 20 units of time ind <- findInterval(20, s$time) cbind(s$surv[ind], s$time[ind]) ## 2. possibility to get the probability for surviving 20 units of time ind <- s$time >= 20 sum(ind) / length(ind) Thanks and best regards Andreas

David Winsemius

2010-Dec-10 20:11 UTC

### [R] survival package - calculating probability to survive a given time

On Dec 10, 2010, at 2:07 PM, Andreas Wittmann wrote:> Dear R users, > > i try to calculate the probabilty to survive a given time by using > the estimated survival curve by kaplan meier. > > What is the right way to do that? as far as is see i cannot use the > predict-methods from the survival package? > > library(survival) > set.seed(1) > time <- cumsum(rexp(1000)/10) > status <- rbinom(1000, 1, 0.5) > > ## kaplan meier estimates > fit <- survfit(Surv(time, status) ~ 1) > s <- summary(fit) > > ## 1. possibility to get the probability for surviving 20 units of > time > ind <- findInterval(20, s$time) > cbind(s$surv[ind], s$time[ind])See if this helps: > head(which(s$surv < 0.5)) [1] 368 369 370 371 372 373 > plot(fit) > abline(h=0.5) > abline(v=s$time[368])> > ## 2. possibility to get the probability for surviving 20 units of > time > ind <- s$time >= 20 > sum(ind) / length(ind)-- David Winsemius, MD West Hartford, CT

Terry Therneau

2010-Dec-13 18:52 UTC

### [R] survival package - calculating probability to survive a given time

- ------- included message -------- i try to calculate the probabilty to survive a given time by using the estimated survival curve by kaplan meier. What is the right way to do that? as far as is see i cannot use the predict-methods from the survival package? ---- end inclusion -------- The survfit function directly estimates the probability you want, no predict method is needed. It is similar to quantile(x, 1:9/10), in that you would not use predict on that either. As to getting the value at a specific time, use summary(fit, time=20) This correctly interpolates the step function when "20" is exactly one of the event times. Terry Therneau