1

I have a Cox regression which employs strata() and a tt().

How can i plot this? All the usual suspects (ggsurvplot, hazard.ratio.plot) dont work for a coxph.penalformat.

Here is some dummy data:

set.seed(132456)
'dummy survival data'
df<-data.frame(id=seq(1,1000,1), df<-data.frame(id=seq(1,1000,1), event=rep(0,1000),time=floor(runif(1000,7,10)),group=floor(runif(1000,0,2)), 
               var1 = rnorm(1000, 1, 3), var2 = seq(1,1000), ID=rep(c("A","B","c","D", 250))))
'set events for a few random subjects'

id_list<-c(as.numeric(floor(runif(500,1,1000))))
df$event[df$id %in% id_list]<-1

'set survival times for events'
t_list<-c(as.numeric(floor(runif(394,1,5))))
df2<-df[df$event==1,]
df2$time<-t_list


'combine data'
df<-rbind(df,df2)
summary(df)

'Set up cox regression:'
library(survival)
coxph(Surv(time , event) ~ tt(var2) + strata(group)+ var1+frailty(ID) ,data= df)

Is there a way to plot a curve like this, or is it just not possible, due to the frailty() term? If this is not possible, can I manually plot hazard rates for each covariate?

Thanks for any advice!!!

Juan
  • 171
  • 1
  • 12
  • `Error in unique(x[!is.na(x)]) : object 'ID' not found` – IRTFM Jan 28 '20 at 17:59
  • Fixed. it Thanks! – Juan Jan 28 '20 at 18:22
  • The problem with using `basehaz` is not due to the `frailty` term but rather due to the `tt` term. THe author of the survival package has suggested using the `coxme` package instead of `coxph` with `frailty` terms. – IRTFM Jan 28 '20 at 18:37
  • Yes indeed the `tt`term is not helping. I might need to look into the `coxme`then. Do you know if the syntax is much different to `coxph`? I built a full thesis on using it.....;) – Juan Jan 28 '20 at 18:52
  • Furthermore, your `time` variable appears unsuitable for this analysis. When I run: `with(df, plot(time,var2))` it appear there are only a few distinct values of `time` – IRTFM Jan 28 '20 at 18:52
  • Well this data is really just a dummy with no underlying function whatsoever. I cant upload my data as it s way too large – Juan Jan 28 '20 at 18:53
  • I think you may need better statistical consultation than you are likely to get here. The `tt` argument is supposed to be given a function object and that does not seem to be what you are doing. I worry that you are making this unnecessarily complex. – IRTFM Jan 28 '20 at 19:04
  • It is worth a try, but yes that is what I think too. The very basic model is covered quite extensively but additional issues are rather hard to find solutions for. Thanks anyway – Juan Jan 28 '20 at 19:22

0 Answers0