This question concerns survival data i.e. a triple that is (enter, exit, event)
. My data is structured such that for each individual id
, I can have event = 1
only once. I want to generate a survival table which shows for any given age, how many individuals have experienced the event.
To get an idea of what my data is like, the survival curve looks like this:
df <- structure(list(id = c("23KU", "24N7", "277J", "29Q9", "2AWB",
"2MVW", "2RLV", "2U7E", "2WQP", "2WUW"), enter = c(0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L), exit = c(25.2676249144422, 13, 22.1409993155373,
46.4695414099932, 31.2772073921971, 5, 29.2320328542094, 19.8329911019849,
31.8986995208761, 31.9534565366188), event = c(0L, 1L, 0L, 0L,
0L, 1L, 0L, 0L, 0L, 0L)), row.names = c(NA, 10L), class = "data.frame")
fit <- survfit(Surv(enter, exit, event) ~ 1, df)
ggsurvplot(fit)
Clearly, not every individual experiences the risk. But when I generate the risk table, the number at risk goes to 0
, which I cannot fathom.
> risk_df <- ggsurvtable(fit, data = df)
> risk_df[["risk.table"]][["data"]]
time n.risk n.event
1 0 10 0
2 5 10 1
3 10 9 0
4 15 8 1
5 20 7 0
6 25 6 0
7 30 4 0
8 35 1 0
9 40 1 0
10 45 1 0
The column n.event
clearly show the event only occurred twice, so the number at risk should be 8
till the very end.
Any explanation would be appreciated, and any suggestion to get the proper risk table. I don't want to plot it, I wish to just export the table as a dataframe to convert to latex.