0

I'm struggling to set a dataframe for multistate survival analysis. Here is the reproducible example with only 3 individuals (ID). This is only a part of the multistate.

f <- structure(list(ID = c(3, 4, 5), time_to_end = c(30, 36, 36)), row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"))

f.long<–structure(list(ID = c(3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5), resp_pois = c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), time = c(6, 12, 18, 24, 30, 36, 42, 48, 6, 12, 18, 24, 30, 36, 42, 48, 6, 
12, 18, 24, 30, 36, 42, 48)), row.names = c(NA, -24L), class = c("tbl_df", "tbl", "data.frame"))

f includes 3 individual taking a new drug and observed for time_to_end. f.long includes the biochemical response at different time points. E.g., ID 3 immediately respond to the drug up to 24 months, but at 30 months there is evidence of lack of biochemical response, while ID 4 shows only an isolated response at 24 months but never again or before.

I'm trying to manage this reversible condition between response and no-response with tmerge, as follows:

f.merge <- tmerge(f %>% select(ID), f, id=ID, tstart = 0, tstop = time_to_end)
f.merge <- tmerge(f.merge, f.long, id=ID, response=event(time, resp_pois))
survfit(Surv(tstart, tstop, response)~1, data=f.merge)

The problem is that tmerge interpretes every resp==1 as a new event, so at the end the survfit function give 5, instead of 2.

Can someone suggest any solution? Am i probably misusing tmerge?

Devanto
  • 33
  • 5

1 Answers1

0

I got this answer from Prof Terry Therneau by e-mail

Okay, 0. When debugging a purported issue with the survival package, my first step is run in an R session with the survival package loaded, and NOTHING else.

  1. I can't read your data set: I'm getting a syntax error somewhere. But by cutting and pasting, I was able to create a "de tibbled" version of the data.
  2. But what exactly is the data? The variable name "resp_pois" means nothing to me. You gave some information on where you want to go, but none about where you are starting. I will hazard a guess that you are dealing with panel data, i.e., subjects come in at regular intervals and you mesure their state at each visit?
  3. Now, tmerge has no way to distinguish a data set with multiple heart attacks, and one row per attack; from a panel study data set.
Devanto
  • 33
  • 5
  • Those comments seems to be useful to improve your question, but not an answer for that. Could you please adjust your question accordingly and delete the answer? – Fernando Barbosa May 29 '22 at 12:27