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 easy.

Arguments:

x: a list of dataframe, each dataframe contains only 3 columns, 1) patient id; 2) time when covariate changes; 3) value that the covariate changes to

y: a dataframe that contains patient id, survival time, last follow up status and other non-time-varying 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 that will be kept, default is all variables in "y"

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"))

Generate a results table (as a data frame) for a given fitted model. The data frame can work with xtable package nicely to generate tex code for the final PDF file.

This set of functions will work with most available fitted models (objects of class) , including but not limited to aov, coxph, glm, lm, loess, manova, mlm, nls, glm, Glm, lrm, ols, cph, nlme.

The main function will return a table (data frame) that has all (or selected) predictors and/or linear combinations in rows. It will contain columns: Variable name, Estimates, s.e., OR/HR, CI, p values. Users can easily choose the columns that they want to present by working with the data frame.

Variable Estimate s.e. OR or HR 95% CI p
Predictor 1 0.53 0.12 1.20 (1.11, 3.50) <0.001
Predictor 2 1.58 0.86 2.60 (1.11, 3.50) 0.03
Predictor 3 2.58 0.35 3.84 (1.11, 3.50) 0.005
Linear combination 1 3.57 0.42 2.13 (1.11, 3.50) 0.80
Linear combination 2 2.89 1.02 3.52 (1.11, 3.50) 0.25

This set of functions are currently under development. Please come back soon. If you have any suggestions or comments, please drop me a message at alex.zhao@vanderbilt.edu.

Topic revision: r7 - 21 Aug 2013, AlexZhao
 

This site is powered by FoswikiCopyright © 2013-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback