get_surv_prob: Get Survival Probability at Specified Times

Description Usage Arguments Value Examples

Description

get_surv_prob retrieves the survival probability at a specific time from a survival curve object from the survival::survfit function. The survival curve object can only have one group.

Usage

1
get_surv_prob(fit, times)

Arguments

fit

survival::survfit object.

times

Vector of times to lookup survival probabilities.

Value

Vector of survival probabilities based on the input times.

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
library("survival")

# Get Survival Probabilities Based on Whole Cohort
fit <- survfit(Surv(time, status) ~ 1, data = colon)
times <- c(100, 200, 300)
get_surv_prob(fit, times)

# Get Survival Probabilities for Each rx Group
library("purrr")
library("dplyr")
library("tidyr")

surv.prob.res <- 
  colon %>%
  split(.$rx) %>%
  map(~ survfit(Surv(time, status) ~ 1, data = .)) %>%
  map(get_surv_prob, times)

surv.prob.res.df <- as_data_frame(surv.prob.res)
colnames(surv.prob.res.df) <- names(surv.prob.res)
surv.prob.res.df <-
  surv.prob.res.df %>%
  mutate(surv_prob_time = times)

gather(surv.prob.res.df, "group", "surv_prob", Obs:`Lev+5FU`)

tinyheero/survutils documentation built on May 31, 2019, 3:36 p.m.