Skip to content

Instantly share code, notes, and snippets.

@n8thangreen
Last active December 15, 2016 09:55
Show Gist options
  • Save n8thangreen/7335129 to your computer and use it in GitHub Desktop.
Save n8thangreen/7335129 to your computer and use it in GitHub Desktop.
Generate subdistribution hazard time values
subdistn <- function(survData){
## substitute in later times to change risk sets
## time representation appropriate for subdistribution hazards
##
## Accounts for administrative censoring
## note that within a specific organism subset the maximum time
## may be from a patient infected by a different organism
## default entries
survData$time2disch <- survData$time2death <- survData$time
## event times of INFECTED database, DISCHARGE alive (censored at death)
mtime1 <- max(survData[survData$infstatus==1, "time"], na.rm=TRUE) # maximum infected database time, Dead=TRUE
# not actually the administritive censoring time which is bigger than this
survData$time2disch[survData$infstatus==1 & survData$event & survData$missingType] <- mtime1+1
## event times of INFECTED database, DEATH (censored at discharge alive)
survData$time2death[survData$infstatus==1 & !survData$event & survData$missingType] <- mtime1+1
## event times of UNINFECTED, DISCHARGE alive (censored at death)
mtime0 <- max(survData[survData$infstatus==0, "time"], na.rm=TRUE) # maximum uninfected database time, Dead=TRUE
survData$time2disch[survData$infstatus==0 & survData$event & survData$missingType] <- mtime0+1
## event times of UNINFECTED, DEATH (censored at discharge alive)
survData$time2death[survData$infstatus==0 & !survData$event & survData$missingType] <- mtime0+1
survData
}
## END FUNCTION ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment