Skip to content

Survival Analysis

Eric Littmann edited this page Aug 3, 2017 · 6 revisions

Survival Analysis from CID (2012)

yingtools2 contains functions for running univariate and multivariate cox proportional hazards modeling, but this requires a few dependencies:

library(plyr)
library(dplyr)
library(survival)
library(yingtools2)
data("cid94")

Of note, be sure to load plyr before dplyr


1. Univariate Analysis

  • If we wanted to assess whether patient age at bmt predicts Enterococcus domination (greater than 30% relative abundance), left censoring up to first stool sample collected, we could create a cox proportional hazards model using:

    stcox(data=pt.cid94,"enterodom30", "agebmt", starttime="firstsampday")
    


2. Univariate Analysis with Multiple Predictors

  • To perform univariate analyses for a vector of predictors, similarly you could run:

    xvars <-  c("agebmt","sex","primary.dx","priorabx.14d","bmt.tcell.depletion","bmt.cord","fever","vanco_iv","fluoroquinolone","metronidazole","betalactam")
    univariate.stcox(data=pt.cid94, "enterodom30", xvars, starttime="firstsampday") 
    

  • Notice how time dependent variables are marked with (td) in the output. Time dependent variables have corresponding columns in the dataframe with the same name with _day added to the variable name which contains the day (relative to time 0) that event occurred. Anytime you run stcox on a dataframe containing a variable and column of the same name with _day at the end, that variable will be treated as time dependent. If you remove the _day column, that variable will no longer be treated as time-dependent.

3. Multivariate Analysis

  • To test the same set of predictors on Enterococcus domination, then testing variables with pvalues less than 0.2 in a multivariate analysis, you can run:

    univariate.stcox("enterodom30", xvars, starttime="firstsampday", data=pt.cid94, multi = T, multi.cutoff = 0.2) 
    

  • Remember, it is important to align all variables by the same time zero before running these kinds of analyses