Builds a binary matrix (0/1/NA) encoding whether each individual had each long-term
condition (LTC) at each time point from 0 to l
, based on their age of onset. The matrix
includes all LTCs, including those used to determine censoring and failure. However, the
presence of fail_code
or cens_code
still triggers NA values after their onset.
make_state_matrices(
data,
id = "link_id",
ltc = "reg",
aos = "aos",
l = 111,
fail_code = "death",
cens_code = "cens"
)
A matrix with (l + 1) * number of LTCs
rows and
one column per unique individual. Values are 1 after onset, 0 before, and NA after censor/fail.
Rows are named <ltc>_<time>
, and columns are individual IDs.
A data frame containing one row per condition occurrence.
Name of the column identifying individuals.
Name of the column containing LTC labels.
Name of the column giving age of onset (or time of onset) for each LTC.
The maximum time index (inclusive); matrix has l + 1
time rows per LTC.
Label in ltc
indicating a failure event (e.g., death).
Label in ltc
indicating censoring.
@author Marc Delord
Delord M, Douiri A (2025) doi:10.1186/s12874-025-02476-7