Skip to content

Instantly share code, notes, and snippets.

View PhilipPallmann's full-sized avatar

Philip Pallmann PhilipPallmann

  • Cardiff University
  • Cardiff, UK
View GitHub Profile
@PhilipPallmann
PhilipPallmann / ggsurv.R
Last active August 29, 2015 14:03 — forked from mattbaggott/ggsurvival.R
Draw ggplot2-style Kaplan-Meier curves (slightly modified version of mattbaggott/ggsurvival.R).
ggsurv <- function(f.survfit, f.CI="default", f.shape=3){
require(ggplot2, quietly=TRUE)
# initialise frame variable
f.frame <- NULL
# check if more then one strata
if(length(names(f.survfit$strata)) == 0){
# create data.frame with data from survfit
@PhilipPallmann
PhilipPallmann / toSurv.R
Last active August 29, 2015 14:03
Convert a survival dataset in wide format (with numbers of survivors in columns) to a list with variables 'time' and 'event' as required for survival analysis in R.
toSurv <- function(data, times){
if(ncol(data)!=length(times)){
stop("'data' and 'time' must be equal in length.")
}
last <- ncol(data)
eventlist <- timelist <- list()