I'm trying to run the following code, including survival::tmerge() to conduct survival analysis with time-varying covariates, but i always get the error
Error in tmerge(df.merge %>% select(CODE98, id), df.long, id = CODE98, : neither a tstop argument nor an initial event argument was found>
I wrote this code some months ago and it worked properly. I noticed that it started giving error after updating R to version 4.0.2
df <-
structure(list(CODE98 = structure(c(4, 8, 9, 10, 13, 17, 18,
19, 20, 23, 26, 28, 30, 32, 33, 35, 37, 38, 41, 42, 45, 46, 47,
49, 50, 51, 53, 54, 56, 59, 61, 62, 65, 68, 69, 70, 72, 73, 77,
78, 80, 82, 84, 86, 87, 88, 89, 90, 91, 93), label = "Subject ID code/Codice di soggetto"),
X_DATEL = structure(c(10653, 10744, 10533, 10735, 10611,
10556, 10744, 10764, 10673, 10751, 10541, 10576, 10610, 10625,
10709, 10667, 10534, 10540, 10646, 10715, 10632, 10757, 10611,
10589, 10618, 10569, 10638, 10701, 10681, 10743, 10709, 10632,
10666, 10701, 10555, 10673, 10701, 10681, 10680, 10701, 10604,
10520, 10520, 10764, 10694, 10736, 10749, 10666, 10730, 10695
), label = "Date of Baseline fasting blood/urine", format.sas = "DATE", class = "Date"),
Y_DATEL = structure(c(11797, NA, 11748, 11792, NA, 11734,
11773, NA, 11779, 11811, 11734, 11748, NA, 11769, 11790,
11811, 11699, NA, 11734, 11839, NA, 11783, 11741, 11741,
NA, NA, 11786, 11783, NA, 11811, 11804, 11837, NA, 11839,
NA, 11839, NA, 11850, 11734, NA, 11837, 11699, NA, 11781,
NA, 11809, 11783, 11804, 11825, NA), label = "Date of Followup 1 fasting blood/urine", format.sas = "DATE", class = "Date"),
Z_DATEL = structure(c(12934, 12957, 12901, NA, NA, 12832,
NA, 12964, 12920, NA, 12831, 12831, 12874, 12861, 12944,
NA, 12896, NA, 12824, 12969, NA, 12957, 12891, 12852, NA,
NA, 12878, 12962, NA, 12885, NA, 12884, NA, 13277, NA, NA,
NA, 12922, 12852, NA, 12857, 12772, NA, NA, 12922, 12950,
13284, 12874, 12934, NA), label = "Date of Followup 2 fasting blood/urine", format.sas = "DATE", class = "Date"),
Q_DATEL = structure(c(13934, NA, 13977, NA, NA, 13976, NA,
14039, 13976, NA, 13948, 13934, 13969, 14057, 13969, NA,
13906, NA, 13941, 14046, 13969, 13993, NA, 13941, NA, NA,
13973, 13978, NA, NA, NA, 13990, NA, 13945, 13993, NA, NA,
NA, 14026, NA, 13913, 13913, NA, NA, NA, 13927, 13864, 13920,
13955, 14028), label = "Date of Followup 3 fasting blood/urine", format.sas = "DATE", class = "Date"),
C_DATEL = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 15888, NA, NA, NA, 15860, NA, NA, NA, 15922, NA, NA,
NA, NA, 16003, NA, NA, NA, NA, NA, NA, NA, 15873, NA, NA,
16016, NA, NA, NA, 15965, NA, NA, 15980, NA, NA, NA, NA,
15952, NA, 15869, 15868), label = "Date of Followup 4 fasting blood/urine", format.sas = "DATE", class = "Date"),
X_AGEL = structure(c(79, 80, 78, 83, 90, 81, 78, 84, 74,
87, 75, 68, 71, 66, 73, 75, 67, 83, 66, 67, 75, 69, 83, 65,
67, 74, 85, 71, 73, 83, 85, 75, 88, 74, 85, 66, 82, 88, 69,
84, 66, 69, 86, 86, 74, 83, 72, 78, 66, 80), label = "Age at Baseline fasting blood/urine(yrs)"),
Y_AGEL = structure(c(82, NA, 81, 86, NA, 84, 81, NA, 77,
90, 78, 72, NA, 69, 76, 78, 70, NA, 69, 70, NA, 72, 86, 69,
NA, NA, 88, 74, NA, 86, 88, 78, NA, 77, NA, 69, NA, 91, 71,
NA, 70, 72, NA, 89, NA, 86, 75, 81, 69, NA), label = "Age at Followup 1 fasting blood/urine(yr"),
Z_AGEL = structure(c(85, 86, 84, NA, NA, 87, NA, 90, 80,
NA, 81, 74, 77, 72, 79, NA, 73, NA, 72, 73, NA, 75, 89, 72,
NA, NA, 91, 77, NA, 89, NA, 81, NA, 81, NA, NA, NA, 94, 74,
NA, 73, 75, NA, NA, 80, 89, 79, 84, 72, NA), label = "Age at Followup 2 fasting blood/urine(yr"),
Q_AGEL = structure(c(88, NA, 87, NA, NA, 91, NA, 93, 83,
NA, 84, 78, 80, 75, 82, NA, 76, NA, 75, 76, 84, 78, NA, 75,
NA, NA, 94, 80, NA, NA, NA, 84, NA, 83, 94, NA, NA, NA, 78,
NA, 75, 78, NA, NA, NA, 92, 80, 87, 75, 89), label = "Age at Followup 3 fasting blood/urine(yr"),
C_AGEL = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 90, NA, NA, NA, 87, NA, NA, NA, 81, NA, NA, NA, NA, 80,
NA, NA, NA, NA, NA, NA, NA, 89, NA, NA, 100, NA, NA, NA,
83, NA, NA, 84, NA, NA, NA, NA, 86, NA, 80, 94), label = "Age at Followup 4 fasting blood/urine(yr"),
X_GPT = structure(c(20, 16, 11, 11, 12, 20, 16, 19, 32, 11,
13, 35, 15, 139, 14, 14, 20, 6, 10, 15, 11, 18, 10, 17, 15,
15, 15, 19, 49, 12, 13, 18, 9, 21, 12, 29, 29, 22, 22, 15,
23, 21, 10, 14, 20, 17, 18, 12, 24, 17), label = "BL GPT (also known as ALT) (U/L)"),
Y_GPT = structure(c(13, NA, 14, 10, NA, 15, 17, NA, 25, 10,
10, 35, NA, 59, 12, 11, 20, NA, 11, 141, NA, 22, 9, 25, NA,
NA, 11, 10, NA, 10, 24, 19, NA, 10, NA, 16, NA, 9, 18, NA,
18, 20, NA, 12, NA, 13, 18, 11, 18, NA), label = "F1 GPT (also known as ALT) (U/L)"),
Z_GPT = structure(c(12, 20, 16, NA, NA, 13, NA, 11, 24, NA,
6, 18, 18, 24, 15, NA, 17, NA, 16, 10, NA, 35, 8, 13, NA,
NA, 26, 11, NA, 14, NA, 17, NA, 17, NA, NA, NA, 11, 16, NA,
14, 20, NA, NA, 17, 11, 14, 8, 24, NA), label = "F2 GPT (also known as ALT) (U/L)"),
Q_GPT = structure(c(16, NA, 19, NA, NA, 12, NA, 9, 21, NA,
10, 18, 18, 60, 13, NA, 18, NA, 12, 11, 11, 19, NA, 41, NA,
NA, 247, NA, NA, NA, NA, 16, NA, 12, 7, NA, NA, NA, 20, NA,
16, 18, NA, NA, NA, 14, 22, 18, 18, 34), label = "F3 GPT (also known as ALT) (U/L)"),
C_GPT = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
12, NA, NA, NA, 12, NA, NA, NA, 15, NA, NA, NA, NA, 20, NA,
NA, NA, NA, NA, NA, NA, 23, NA, NA, 9, NA, NA, NA, 14, NA,
NA, 16, NA, NA, NA, NA, 24, NA, 18, 21), label = "F4 GPT (also known as ALT) (U/L)", format.sas = "BEST"),
X_GOT = structure(c(17, 17, 21, 15, 20, 20, 14, 26, 22, 21,
29, 26, 14, 90, 15, 20, 21, 12, 16, 9, 17, 19, 15, 22, 20,
19, 23, 22, 55, 21, 23, 22, 23, 16, 22, 19, 26, 23, 18, 15,
30, 23, 19, 15, 22, 23, 16, 20, 22, 24), label = "BL GOT (also known as AST) (U/L)"),
Y_GOT = structure(c(12, NA, 13, 15, NA, 19, 16, NA, 25, 15,
24, 31, NA, 47, 12, 18, 17, NA, 20, 74, NA, 21, 12, 29, NA,
NA, 18, 16, NA, 18, 26, 21, NA, 15, NA, 18, NA, 13, 17, NA,
NA, 23, NA, 17, NA, 22, 18, 21, 21, NA), label = "F1 GOT (also known as AST) (U/L)"),
Z_GOT = structure(c(8, 18, 21, NA, NA, 21, NA, 19, 21, NA,
24, 19, 14, 24, 14, NA, 19, NA, 19, 9, NA, 22, 12, 17, NA,
NA, 23, 15, NA, 18, NA, 25, NA, 11, NA, NA, NA, 13, 18, NA,
26, 22, NA, NA, 18, 21, 16, 23, 22, NA), label = "F2 GOT (also known as AST) (U/L)"),
Q_GOT = structure(c(13, NA, 30, NA, NA, 21, NA, 19, 21, NA,
23, 18, 15, 53, 14, NA, 18, NA, 18, 8, 14, 21, NA, 30, NA,
NA, 311, NA, NA, NA, NA, 21, NA, 12, 20, NA, NA, NA, 21,
NA, 23, 22, NA, NA, NA, 22, 17, 28, 20, 36), label = "F3 GOT (also known as AST) (U/L)"),
C_GOT = structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
25, NA, NA, NA, 15, NA, NA, NA, 18, NA, NA, NA, NA, 21, NA,
NA, NA, NA, NA, NA, NA, 29, NA, NA, 16, NA, NA, NA, 18, NA,
NA, 20, NA, NA, NA, NA, 19, NA, 20, 28), label = "F4 GOT (also known as AST) (U/L)", format.sas = "BEST"),
DATA_ULT = structure(c(17395, 13372, 15951, 11908, 11600,
15237, 12312, 14941, 16578, 12355, 15988, 17139, 16059, 15955,
15891, 15672, 15986, 10828, 16751, 15838, 16043, 15917, 13338,
16049, 13072, 13412, 14158, 14719, 11697, 14984, 13668, 17257,
11534, 15277, 16217, 16059, 13525, 13405, 17254, 11334, 14777,
16049, 11737, 12711, 13352, 14321, 15958, 16021, 15888, 16941
), label = "Date of Last Contact as of FUP4 or death", format.sas = "DATE", class = "Date"),
DECEASED = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,
0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1),
label = "Deceased?/Deceduto(a)?")), row.names = c(NA,-50L), class = c("tbl_df", "tbl", "data.frame"))
df.long <- df %>% pivot_longer(cols = c(ends_with("DATEL"), ends_with("AGEL"), ends_with("GPT"), ends_with("GOT")),
names_to = c("time", ".value"), names_sep = "(?<=[XYZQC])_", values_drop_na = TRUE) %>%
select(CODE98, DATEL, AGEL, GPT, GOT)
df.merge <- tmerge(df, df, id=CODE98, tstart=as.numeric(X_DATEL), tstop=as.numeric(DATA_ULT),
deceased=event(as.numeric(DATA_ULT), DECEASED))
df.merge <- tmerge(df.merge %>% select(CODE98, id), df.long,
id=CODE98,
age=tdc(as.numeric(DATEL), AGEL),
gpt=tdc(as.numeric(DATEL), GPT), got=tdc(as.numeric(DATEL), GOT))
Can anybody understand what it is going on? Thanks so much in advance
Solved by Prof. Terry Therneau by e-mail: