getKMcurve: Extract data describing the Kaplan-Meier curve from a...

Description Usage Arguments Value Examples

View source: R/utilities.R

Description

Extract data describing the Kaplan-Meier curve from a survfit object

Usage

1
getKMcurve(km, time.col, event.col, group.col, data)

Arguments

km

A survfit object containing the Kaplan-Meier estimate of the survival function as returned by survfit

Value

A data frame with columns:

Time

The time of the events

Survival

The probability of survival at each event time

stderr

The standard error of the survival estimate

lower

The lower limit of the confidence interval for the survival curve

upper

The upper limit of the confidence interval for the survival curve

Nrisk

The number of patients at risk at each event time

group

(Optional) The group that each observation belongs to if there are multiple patient groups. This will be absent if there is only one group

Examples

 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')

RichardBirnie/survtools documentation built on Aug. 3, 2019, 3:20 a.m.