Data Long Competing Risks Transformation
Transforms short data format to long format for discrete survival modelling in the case of competing risks with right censoring. It is assumed that the covariates are not time varying.
dataLongCompRisks(dataSet, timeColumn, eventColumns, eventColumnsAsFactor=FALSE, timeAsFactor=TRUE)
dataSet |
Original data in short format. Must be of class "data.frame". |
timeColumn |
Character giving the column name of the observed times. It is required that the observed times are discrete (integer). |
eventColumns |
Character vector giving the column names of the event indicators (excluding censoring column). It is required that all events are binary encoded. If the sum of all event indicators is zero, then this is interpreted as a censored observation. Alternatively a column name of a factor representing competing events can be given. In this case the argument "eventColumnsAsFactor" has to be set TRUE and the first level is assumed to represent censoring. |
eventColumnsAsFactor |
Should the argument "eventColumns" be intepreted as column name of a factor variable(logical scalar)? Default is FALSE. |
timeAsFactor |
Should the time intervals be coded as factor? Default is to use factor. If the argument is false, the column is coded as numeric. |
It is assumed, that only one event happens at a specific time point (competing risks). Either the observation is censored or one of the possible events takes place.
Original data set in long format with additional columns
obj: Gives identification number of objects (row index in short format) (integer)
timeInt: Gives number of discrete time intervals (factor)
responses: Columns with dimension count of events + 1 (censoring)
e0: No event (observation censored in specific interval)
e1: Indicator of first event, 1 if event takes place and 0 otherwise
... ...
ek: Indicator of last k-th event, 1 if event takes place and 0 otherwise
Thomas Welchowski welchow@imbie.meb.uni-bonn.de
Gerhard Tutz and Matthias Schmid, (2016), Modeling discrete time-to-event data, Springer series in statistics, Doi: 10.1007/978-3-319-28158-2
Steele Fiona and Goldstein Harvey and Browne William, (2004), A general multilevel multistate competing risks model for event history data Statistical Modelling, volume 4, pages 145-159
Wiji Narendranathan and Mark B. Stewart, (1993), Modelling the probability of leaving unemployment: competing risks models with flexible base-line hazards, Applied Statistics, pages 63-83
# Example with unemployment data library(Ecdat) data(UnempDur) # Select subsample SubUnempDur <- UnempDur [1:100, ] # Convert competing risk data to long format SubUnempDurLong <- dataLongCompRisks (dataSet=SubUnempDur, timeColumn="spell", eventColumns=c("censor1", "censor2", "censor3", "censor4")) head(SubUnempDurLong, 20) # Fit multinomial logit model with VGAM package # with one coefficient per response library(VGAM) multLogitVGM <- vgam(cbind(e0, e1, e2, e3, e4) ~ timeInt + ui + age + logwage, family=multinomial(refLevel=1), data = SubUnempDurLong) coef(multLogitVGM) # Alternative: Use nnet # Convert response to factor rawResponseMat <- SubUnempDurLong[, c("e0", "e1", "e2", "e3", "e4")] NewFactor <- factor(unname(apply(rawResponseMat, 1, function(x) which(x == 1))), labels = colnames(rawResponseMat)) # Include recoded response in data SubUnempDurLong <- cbind(SubUnempDurLong, NewResp=NewFactor) # Construct formula of mlogit model mlogitFormula <- formula(NewResp ~ timeInt + ui + age + logwage) # Fit multinomial logit model # with one coefficient per response library(nnet) multLogitNNET <- multinom(formula=mlogitFormula, data=SubUnempDurLong) coef(multLogitNNET)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.