Search code examples
rsurvival

Plot KM curve using survfit in R without strata


I want to plot a KM curve and get median survival data from the survfit() object but I don't want to split by strata - I want to know the whole population.

fit <- survfit(Surv(Time, Status) ~ Group, data = A)

eg. I don't want to have ~ Group


Solution

  • You then fit a model of the intercept. I generated some example data to illustrate this.

    library(survival)
    
    df <- data.frame(Status=c(0,1,0,1,0,1,0,1,0,1,0,1), 
                     Time=c(30,10,15,30,3,1,14,30,28,30,20,30))
    
    df$forKM <- with(df, Surv(Time, Status == 1))
    
    fit <- survfit(forKM ~ 1, data = df)
    plot(fit)
    

    enter image description here

    If you don't want to see the confidence interval in the plot, then you should specify: conf.int=F.