Some datasets record each endpoint in its own pair of columns rather than in one outcome
column. In mgus2, for example, ptime and pstat hold the time to plasma cell malignancy and
whether it occurred, and futime and death do the same for death. A competing-risks analysis
needs one time and one cause per subject: the first endpoint observed, or censoring if none
was. first_event() builds that response.
Arguments
- endpoints
A named list with one element per endpoint, in priority order for ties. Each element is a list of two vectors of the same length: the time of the endpoint and whether it occurred (logical or
0/1). The names are the states of the response.- censor_at
The time at which rows with no observed event are censored, one number or one per row. The default is the latest of the endpoint times.
- start
Entry times for delayed entry, one per row. With them, the response is a multi-state counting-process response.
Value
A multi-state Surv() response whose states are the endpoint names, in order.
Details
For each row, the endpoint with the earliest observed event becomes the cause, and its time
becomes the event time. Ties go to the endpoint listed first. A row with no observed event is
censored at the latest of its endpoint times (the last time it was known to be event-free), or
at censor_at if given. A row with a missing endpoint time is missing.
first_event() can be used on the left-hand side of a model formula, where its columns are
found in data, such as
first_event(list(pcm = list(ptime, pstat), death = list(futime, death))) ~ age.
Warnings
A row whose event is recorded after another endpoint's follow-up had already ended without an event gives a warning. This often means the time columns don't share an origin or a unit.
See also
aalen_johansen(), fine_gray(), and the other competing-risks models that take the
response.
Examples
# Subject 1 has endpoint "a" at time 5, subject 2 has "b" at time 8, and subject 3 is censored
# at time 9.
first_event(list(
a = list(c(5, 9, 4), c(1, 0, 0)),
b = list(c(7, 8, 9), c(0, 1, 0))
))
#> <Surv[3]: mright> states: a, b
#> [1] 5:a 8:b 9+
# In a formula, with the columns found in `data`
mgus <- data.frame(
ptime = c(30, 45, 70, 72, 80, 95, 110, 120),
pstat = c(1, 0, 0, 1, 0, 0, 1, 0),
futime = c(40, 45, 70, 90, 80, 120, 130, 120),
death = c(0, 1, 1, 0, 1, 0, 1, 0)
)
aalen_johansen(
first_event(list(pcm = list(ptime, pstat), death = list(futime, death))) ~ 1,
data = mgus
)
#> <aalen_johansen> first_event(list(pcm = list(ptime, pstat), death = list(futime, death))) ~ 1
#> n = 8. Events: pcm = 3, death = 3
#>
#> Cumulative incidence at the last time (plain limits):
#> cause time estimate std_error conf_low conf_high
#> pcm 120 0.375 0.1712 0.03953 0.7105
#> death 120 0.375 0.1712 0.03953 0.7105