Skip to content

Instantly share code, notes, and snippets.

@beanbear
beanbear / groupSurvival.R
Created August 18, 2019 01:24 — forked from ShixiangWang/groupSurvival.R
two R functions used to separate continuous variable into two group for survival analysis, then plot the result.
library(survival)
library(survminer)
groupSurvival <- function(df, event="OS_IND", time="OS", var=NULL, time.limit=NULL, interval=c("open","close"),
method=c("quartile", "mean", "median", "percent", "custom"), percent=NULL,
step=20, custom_fun=NULL, group1="High", group2="Low"){
#'@param df a data.frame at leaset including three column which refer to survival info and variable used to
#' set group.
#'@param event The status indicator, normally 0=alive, 1=dead. Other choices are TRUE/FALSE (TRUE = death) or 1/2 (2=death).
#'For interval censored data, the status indicator is 0=right censored, 1=event at time, 2=left censored, 3=interval censored.