duplicate {xhaz} | R Documentation |
duplicate function
Description
Duplicate data for survival analysis in the context of
competing risks, where an individual can experience only one of alternative
events, using the Lunn & McNeil (Biometrics, 1995) approaches.
Duplication of data proceeds as follows: Suppose that we study J
distinct types of events. Each observation concerning a given subject is
duplicated J
times, with one row for each type of event. In addition,
(J-1)
dummy variables are created, each indicating the type of event
in relation with that observation (delta.j=1
if the event of type j
is the observed one and 0
otherwise).
Since, for a given subject, only the first occurring event is considered,
the status indicator equals 1
for that event and 0
for all the
others. In the case of a censored observation (dropout or administrative
censoring), the same principle applies also: duplication of each subject's
data is made J
times with (J-1)
dummy variables and a status
indicator equal to 0
for all observations.
Usage
duplicate(status, event, data)
Arguments
status |
the censoring status indicator (numeric vector), 0=alive, 1=dead. |
event |
the indicator of the event type (numeric vector). By default, the event==0 acts as the censoring indicator. |
data |
a data frame containing the data to duplicate. |
Value
A data.frame containing the duplicated data with the new dummy
variables, named delta.number_of_the_event
, indicating the type of
event.
Author(s)
Roch Giorgi
References
Lunn M and McNeil D. Applying Cox regression to competing risks. Biometrics 1995;51:524-532 (PubMed)
Examples
## Create the simplest test data set
data1 <- data.frame(futime = c(1, 2, 5, 2, 1, 7, 3, 4, 8, 8),
fustat = c(0, 1, 1, 1, 0, 0, 1, 0, 1, 1),
firstevent = c(0, 2, 1, 2, 0, 0, 1, 0, 2, 2),
x = c(1, 0, 0, 1, 0, 1, 1, 1, 0, 0))
## Duplicate data1 with firstevent == 0 as the censoring indicator.
dupli.data <- duplicate(status=fustat, event=firstevent, data=data1)
data2 <- data.frame(futime = c(10, 2, 7, 3, 4, 9, 13, 2, 5, 9),
fustat = c(0, 1, 1, 1, 0, 0, 1, 0, 1, 1),
firstevent = c(3, 2, 1, 2, 3, 3, 1, 3, 2, 2),
x = c(1, 0, 0, 1, 0, 1, 1, 1, 0, 0))
## Duplicate data1 with firstevent == 3 as the censoring indicator.
dupli.data <- duplicate(status = fustat,
event = firstevent == 3,
data = data2)
# Joint modeling
coxph(Surv(futime, fustat) ~ delta.2 + x + delta.2:(x), data = dupli.data)
coxph(Surv(futime, fustat) ~ delta.1 + x + delta.1:(x), data = dupli.data)