
Add time-to-event (TTE) follow-up outcomes to a transplant cohort
Source:R/add_time_to_event_variables.R
add_txf_outcomes.Rd
Uses the cohort's file_key
attribute (as set by your SRTR load helpers)
to locate and load the corresponding follow-up table, then derives:
Arguments
- df
A data frame representing a transplant cohort (one row per recipient or transplant). Must include a
TRR_ID
column and have an attributefile_key
(a string) indicating the originating SRTR table key (e.g.,"KI_txf"
). The companion follow-up key is inferred as the same prefix with"F"
inserted after the first two characters (e.g.,"KI_Ftxf"
).
Value
The input df
with additional columns:
- FIRST_FU_MALIG_DATE
Date of first follow-up malignancy (per TRR).
- FIRST_FU_REJ_DATE_ORG
Date of first acute rejection per organ (wide columns by organ code).
Existing columns/attributes of df
are preserved.
Details
FIRST_FU_MALIG_DATE
— first follow-up malignancy date perTRR_ID
FIRST_FU_REJ_DATE_{ORG}
— first acute rejection date per organ code (e.g.,FIRST_FU_REJ_DATE_KI
,FIRST_FU_REJ_DATE_PA
)
The function limits the follow-up load to the cohort's TRR_ID
s for
efficiency, and merges the derived dates back into df
.
This helper:
Infers the follow-up table key from
attr(df, "file_key")
.Loads the follow-up subset for the cohort's
TRR_ID
s viaload_srtr_file()
.Normalizes organ to a two-letter code (
ORG_TYPE
:= first two characters ofORG_TY
), selects core follow-up fields, and orders byTRR_ID
andTFL_PX_STAT_DT
.Computes the earliest malignancy date per
TRR_ID
whereTFL_MALIG == "Y"
.Computes the earliest acute rejection date per (
TRR_ID
,ORG_TYPE
) whereTFL_ACUTE_REJ_EPISODE
indicates at least one treated episode, and pivots to wide organ-specific columns.Left-joins both results back to
df
.
Assumptions/requirements
The follow-up table contains:
TRR_ID
,ORG_TY
,TFL_PX_STAT_DT
,TFL_MALIG
, andTFL_ACUTE_REJ_EPISODE
.TFL_PX_STAT_DT
should be aDate
; if stored asYYYYMMDD
, convert upstream (e.g.,as.Date(as.character(x), "%Y%m%d")
).Rejection is identified by the labeled value
"1: Yes, at least one episode treated with anti-rejection agent"
. Adjust the filter if your coding differs.
Notes
Combined organ codes (e.g.,
"HL"
) are not split; they will produce a columnFIRST_FU_REJ_DATE_HL
. If you prefer to split into heart/lung, duplicate those rows before pivoting.This function only derives event dates. To build full TTE variables (censor date, indicator, elapsed time), pass these dates to your
srtr_time_to_event()
helper along with transplant and last-follow-up dates.
Examples
if (FALSE) {
# df loaded earlier, e.g., df <- load_srtr_file("KI_txf")
attr(df, "file_key")
#> "KI_txf"
df2 <- add_txf_outcomes(df)
names(df2)
# ... includes FIRST_FU_MALIG_DATE, FIRST_FU_REJ_DATE_KI, etc.
# Then compute time-to-event from transplant date:
df2 <- srtr_time_to_event(
df2,
event_date = FIRST_FU_MALIG_DATE,
start_date = REC_TX_DT,
censor_date = TFL_LAFUDATEKI,
prefix = "REC_MALIG"
)
}