Does anyone have suggestions? Thanks! quaildoc wrote: > > I am having trouble formatting some survival data to use in a time > dependent cox model. My time dep. variable is habitat and I have it > recorded for every day (with some NAs). I think it is working properly > except for calculating the death.time. This column should be 1s or 0s and > as I have it only produces 0s. Any help will be greatly appreciated. > > > http://www.nabble.com/file/p25881478/Survival_master2.csv > Survival_master2.csv > > > > Here is my code: > sum(!is.na(surv[,16:726])) > > surv2<-matrix(0,12329,19) > colnames(surv2)<-c('start', 'stop', 'death.time', > names(surv)[1:15],'habitat') > row<-0 # set record counter to 0 > for (i in 1:nrow(surv)) { # loop over individuals > for (j in 16:726) { # loop over 726 days > if (is.na(surv[i, j])) next # skip missing data > else { > row <- row + 1 # increment row counter > start <- j - 11 # start time (previous day) > stop <- start + 1 # stop time (day) > death.time <- if (stop == surv[i, 4] && surv[i, 5] ==1) 1 else > 0 > # construct record: > surv2[row,] <- c(start, stop, death.time, unlist(surv[i, > c(1:15, j)])) > } > } > } > surv2<-as.data.frame(surv2) >
-- View this message in context: http://www.nabble.com/Time-Dependent-Cox-Model-tp25881478p25893488.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.