# Please do not hesitate to contact either Dan (Dan.Nussey@ed.ac.uk) or Rachael (Rachael.Wilbourn@ed.ac.uk) if you encounter a problem # with this script. #========================================================================================================================================= # The cox proportional hazards model computes the multiplicative effect of the included covariates on the estimated baseline hazard/ # mortality rate. The models below estimate the multiplicative effect of telomere length on baseline mortality rate. Telomere length will # first be transformed using a standard normal transformation, defining a standard deviation difference as the unit of analysis, which is # needed in order to standardise TL variation among studies. Before you can run the models you will first need to put together a data file # in excel that includes as many of the following variables as possible: # Individual_ID # start_time (this is the moment/year of blood sampling) # end_time (this is the moment/year the study stopped the following of individuals) # survival_status (status at the end_time of the survey: 0=survived; 1=disappeared) # telomere_length (for qPCR the t/s ratio values are preferred) # sex (0=female; 1=male) # age_at_blood_sampling #Please make sure that you have used the same variable headers as listed above and then save the excel file using the file format *.txt #========================================================================================================================================= #The code below will load the data. You will need to specify the data directory locating your file. ####IMPORTANT#### # 1 Please match the decimal character you used in excel with the code below. Currently the decimal is the default "." If you used a "," # you will need to specify that in the code below. # 2 Please write an NA in every empty cell in your excel file. This will make sure that R understands that these cells are empty. rm(list = ls(all = TRUE)) telodata<-read.table(file="XXXXX",header=TRUE,dec=".",na.strings=c("NA"),sep="") str(telodata) #This will load the required survival library library(survival) #Here telomere length will be transformed using the standard normal transformation telodata$TL<-(telodata$telomere_length-mean(telodata$telomere_length))/sd(telodata$telomere_length) #statistical models computing the hazard ratio of standardized telomere length ## with mortality data model1<-summary(coxph(Surv(start_time,end_time,survival_status) ~ TL, data=telodata)) model1 ######## IF YOUR DATA CONTAINS LIFESPAN/ CENSORED DATA ######## # please include the following variables and run the following code and alternative model 1 # Individual_ID # surv_time (the survival time of the individual) # censor (censored data 0 = alive, 1 = dead) # telomere_length (for qPCR the t/s ratio values are preferred) # sex (0=female; 1=male) # age_at_blood_sampling rm(list = ls(all = TRUE)) telodata<-read.table(file="XXXXX",header=TRUE,dec=".",na.strings=c("NA"),sep="") str(telodata) #This will load the required survival library library(survival) #Here telomere length will be transformed using the standard normal transformation telodata$TL<-(telodata$telomere_length-mean(telodata$telomere_length))/sd(telodata$telomere_length) #statistical models computing the hazard ratio of standardized telomere length with mortality data model1<-summary(coxph(Surv(surv_time,censor) ~ TL, data=telodata)) model1 #========================================================================================================================================= #### SEX SPECIFIC MODELS #### #subset original dataframe by sex males <- subset(telodata, sex==1) females <- subset(telodata, sex==0) #statistical models computing the hazard ratio of standardized telomere length in males model1b<-summary(coxph(Surv(start_time,end_time,survival_status) ~ TL, data=males)) model1b #statistical models computing the hazard ratio of standardized telomere length in females model1c<-summary(coxph(Surv(start_time,end_time,survival_status) ~ TL, data=females)) model1c #=========================================================================================================================================