My R Functions
Create time intervals data for time-varying covariates in survival analysis
When several time-varying covariates present in survival analysis, creating the dataset with time intervals is no longer as straightforward as it was when only single time-varying covariate was involved. This set of functions (in R) were wrote for the purpose of making this type of data manipulation easier.
Arguments:
x: a list of dataframe, each dataframe includes contains only 3 columns, patient id, time when covariate changs, value that the covariate changes to
y: a dataframe that contains patient id, survival time, last follow up status and other non-timevaring covariates
by.id: variable name for patient id in all datasets
by.time: variable name for time in all datasets
var.status: variable name for last follow up status
var.baseline: varaible names for all other non-timevarying covariates
Call:
require(Hmisc)
source("http://biostat.mc.vanderbilt.edu/wiki/pub/Main/AlexFun/mergeI.R")
load(url("http://biostat.mc.vanderbilt.edu/wiki/pub/Main/AlexFun/data.RData"))
mergeI(x=list(d1,d2,d3), y=d0, by.id="pid", by.time="time", var.status="status", var.baseline=c("gender","race"))