Learn R Programming

discSurv (version 1.1.2)

dataLongCompRisks: Data Long Competing Risks Transformation

Description

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.

Usage

dataLongCompRisks(dataSet, timeColumn, eventColumns)

Arguments

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. It is required that all events are binary and the sum of all event indicators at a given time point, equals one.

Value

  • 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 } }

Details

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.

References

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

See Also

contToDisc, dataLongTimeDep

Examples

Run this code
# 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)

Run the code above in your browser using DataLab