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),
sex = c(1, 0, 0, 1, 0, 1, 1, 1, 0, 0))
## Duplicate data1 with firstevent == 0 as the censoring indicator.
library(xhaz)
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),
sex = 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 + sex + delta.2:(sex), data = dupli.data)
coxph(Surv(futime, fustat) ~ delta.1 + sex + delta.1:(sex), data = dupli.data)
# exemple using ccr.mevents data
ccr.mevents$loc.rec <- as.numeric(ccr.mevents$event == 1)
ccr.mevents$dist.rec <- as.numeric(ccr.mevents$event == 2)
ccr.mevents$death <- as.numeric(ccr.mevents$event == 3)
# Age centered to mean and scaled
ccr.mevents$agecr <- scale(ccr.mevents$age, TRUE, TRUE)
## Duplication of the data with local recurrence as the reference
dupli.ccr.mevents <- duplicate(status = status,
event = event, data = ccr.mevents)
head(dupli.ccr.mevents)
# joint model including overall mortality modelling
fit <- coxph(Surv(time, status) ~ agecr + sexe + stage + delta.2 + delta.3,
data = dupli.ccr.mevents)
fit
# add expected mortality from french life table to the data
library(survexp.fr)
fit.haz <- exphaz(formula = Surv(time, death) ~ 1,
data = dupli.ccr.mevents,
ratetable = survexp.fr, only_ehazard = TRUE,
rmap = list(age = 'age', sex = 'sexe', year = 'date_diag'))
dupli.ccr.mevents$mua <- fit.haz$ehazard * dupli.ccr.mevents$delta.3
# joint model including excess hazard modelling
library(mexhaz)
fit.mort <- mexhaz(
Surv(time, status) ~ delta.2 + delta.3,
data = dupli.ccr.mevents, base = "exp.bs", degree = 3, knots = c(1),
expected = "mua")
fit.mort