Question

I am trying to obtain survival estimates for different people at a specific time.

My code is as follows:

s = Surv(outcome.[,1], outcome.[,2])        
survplot= (survfit(s ~ person.list[,1]))  
plot(survplot, mark.time=FALSE)            

summary(survplot[1], times=4)[1]           

This code creates the survival object, creates a survival curve for each 11 of the people, plots each of the curves, and with the summary function I can obtain the survival estimate for person 1 at time = 4.

I am trying to create a list of the survival estimates for each person at a specified time (time = 4).

Any help would be appreciated.

Thanks, Matt

Was it helpful?

Solution

If all that you say is true, then this is a typical way of generating a list using indices as arguments:

 t4list <- lapply(1:11, function(x) summary(survplot[x], times=4)[1] )
 t4list

If you really meant that you wanted a vector of survival estimates based at that time, then sapply would make an attempt to simply the result to an atomic form such as a numeric vector or a matrix in the case where the results were "multidimensional". I would have thought that you could have gotten a useful result with just:

summary(survplot, times=4)[1]

That should have succeeded in giving you a vector of predicted survival times (assuming such times exist.) If you get too greedy and push out the 'times' value past where there are estimates, then you will throw an error. Ironically that error will not be thrown if there is at least one time where all levels of the covariates have an estimate. Using the example in the help page as a starting point:

fit <- survfit(Surv(time, status) ~ x, data = aml) 
summary(fit, times=c(10, 20, 60) )[1]
#$surv
#[1] 0.9090909 0.7159091 0.1840909 0.6666667 0.5833333
# not very informative about which times and covariates were estimated 
# and which are missing

# this is more informative
as.data.frame( summary(fit, times=c(10, 20, 60) )[c("surv", "time", "strata")])
       surv time          strata
1 0.9090909   10    x=Maintained
2 0.7159091   20    x=Maintained
3 0.1840909   60    x=Maintained
4 0.6666667   10 x=Nonmaintained
5 0.5833333   20 x=Nonmaintained

Whereas if you just use 60 you get an error message:

> summary(fit, times=c( 60) )[1]
Error in factor(rep(1:nstrat, scount), labels = names(fit$strata)) : 
  invalid labels; length 2 should be 1 or 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top