I have a Kaplan Meier object from the R package survival
. I can plot it and etcetera, but I would like to evaluate it at specific time points.
How can I create a function that evaluates the KM estimator at specific time points using the KM object?
library(survival)
KM <- survfit(Surv(time, status) ~ 1,data = lung)
> KM(1)
Error in KM(1) : could not find function "KM"
CodePudding user response:
Use summary()
with the times
argument:
library(survival)
KM <- survfit(Surv(time, status) ~ 1,data = lung)
summary(KM, times = seq(0, 5) * 90)
#> Call: survfit(formula = Surv(time, status) ~ 1, data = lung)
#>
#> time n.risk n.event survival std.err lower 95% CI upper 95% CI
#> 0 228 0 1.000 0.0000 1.000 1.000
#> 90 201 27 0.882 0.0214 0.841 0.925
#> 180 160 36 0.722 0.0298 0.666 0.783
#> 270 108 30 0.575 0.0338 0.513 0.645
#> 360 70 24 0.434 0.0358 0.369 0.510
#> 450 48 16 0.329 0.0356 0.266 0.406
summary(KM, times = seq(0, 5) * 90)$surv
#> [1] 1.0000000 0.8815789 0.7216707 0.5753102 0.4340441 0.3287158