Description Usage Arguments Value Examples
Extract data describing the Kaplan-Meier curve from a survfit
object
1 | getKMcurve(km, time.col, event.col, group.col, data)
|
km |
A survfit object containing the Kaplan-Meier estimate of the
survival function as returned by |
A data frame with columns:
The time of the events
The probability of survival at each event time
The standard error of the survival estimate
The lower limit of the confidence interval for the survival curve
The upper limit of the confidence interval for the survival curve
The number of patients at risk at each event time
(Optional) The group that each observation belongs to if there are multiple patient groups. This will be absent if there is only one group
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | library(survival)
library(survminer)
library(flexsurv)
library(dplyr)
library(survtools)
#load some example data from the flexsurv package
#Survival times of 686 patients with primary node positive breast cancer
#censrec = censoring, 1 = dead, 0 = censored
#rectime = time of death or censoring in days
#recyrs = time of death or censoring in years
#group = prognostic group
data(bc)
#create a survival object
surv.obj <- Surv(recyrs, censrec) ~ group
#simple Kaplan-Meier estimate
surv.km <- survfit(surv.obj, data = bc)
#Get the Kaplan-Meier data
#.col variables should correspond to column names in the data set
km.curve <- getKMcurve(km = surv.km, time.col = 'recyrs', event.col = 'censrec', group.col = 'group', data = bc)
#plot KM
plot(km.curve$Time[km.curve$group == 'Good'], km.curve$Survival [km.curve$group == 'Good'], type="l", ylim=c(0,1),
xlab = 'Time', ylab = 'Survival', col = 'red')
lines(km.curve$Time[km.curve$group == 'Medium'], km.curve$Survival [km.curve$group == 'Medium'], col='green')
lines(km.curve$Time[km.curve$group == 'Poor'], km.curve$Survival [km.curve$group == 'Poor'], col='blue')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.