survival
survival copied to clipboard
feature request: number of id in time-dependent covariate coxph()
Thank you for creating survival!
The output of coxph() using time-dependent covariate displays the number of rows of the data as "n=..." instead of the number of "id", even when "id" is specified. From my understanding, the number of "id" is not return in the "coxph" which makes the post-processing of the output more complicated. It might be useful to also add the number of "id", in addition to the number of rows.
library(survival)
set.seed(42)
n=30
df <-
data.frame(
id = seq_len(n),
eos_time = round(runif(n,100,200)),
eos_event = rbinom(n,1,prob=.2),
event_01 = round(runif(n,20,40)),
event_02 = round(runif(n,60,80)),
grp = rep(c(1,0),each= n/2))
df$eos_time2 <- df$eos_time
df$eos_time2[df$eos_event==0]<-NA
df_tv <-
tmerge(df[,c("id","grp")],df[,c("id","eos_time")],id=id,tstop=eos_time) |>
tmerge(data2=df[,c("id","event_01","event_02")],event_01 = event(event_01),event_01 = event(event_02),id=id) |>
tmerge(data2=df[,c("id","eos_time2")],eos_event = event(eos_time2),id=id)
# same model different n!
# n=30
m <- coxph(Surv(eos_time,eos_event)~grp,data=df)
summary(m)
# n=90
m_tv <- coxph(Surv(time = tstart,time2 =tstop,eos_event)~grp,data=df_tv,id=id)
summary(m_tv)
This is a useful suggestion --- I recently added n.id to the survfit object based on the same thought.
This has now been added: the coxph object has an n.id element, if there was an id argument.