Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: number of id in time-dependent covariate coxph() #250

Open
jaromilfrossard opened this issue Apr 10, 2024 · 1 comment
Open

Comments

@jaromilfrossard
Copy link

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)
@therneau
Copy link
Owner

This is a useful suggestion --- I recently added n.id to the survfit object based on the same thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants