[R] survfit question

David Winsemius dwinsemius at comcast.net
Fri Sep 10 03:19:02 CEST 2010


On Sep 9, 2010, at 8:50 PM, andre bedon wrote:

> I am attempting to graph a Kaplan Meier estimate for some claims  
> using the survfit function. However, I was wondering if it is  
> possible to plot a cdf of the kaplan meier rather than the survival  
> function. Here is some of my code:
>
It's not really the cdf of the KM since the KM is just an estimator.  
Yeah, I know, picky, picky.

> library(survival)
> Surv(claimj,censorj==0)

I'm reasonably sure you need to assign that to something (unless its  
purpose is just to test the syntax.)

> survfit(Surv(claimj,censorj==0)~1)
> surv.all<-survfit(Surv(claimj,censorj==0)~1)
> summary(surv.all)
> plot(surv.all)
> I would really appreciate any assistance. Thank you.

The survival function is just 1 minus the CDF, (and vice versa). You  
didn't provide any data, but we can use the aml dataframe in survival:

library(survival)
surv.all<-survfit(Surv(time,status)~1, data=aml)
str(surv.all)   # x-coord is "time" and S_KM(t) is "surv"
plot(surv.all$time, 1-surv.all$surv, type="s", ylim=c(0,1))

So that's the KM estimator of the CDF. Doesn't inherit the nice  
features of the plot.survfit function, though. It's also going to be  
more messy if you have two/+ groups

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list