1

when applying ggforest() to a coxph object I get the follwoing error message

error in ggforest(res.cox3, data = Selection_cox) :
class(model) == "coxph" are not all TRUE

res.cox3is the output of coxph() which includes a tt term, strata and is of class:

> class(res.cox3)
[1] "coxph.penal" "coxph"  

I get the same message for the following dummy data:

set.seed(132456)
'dummy survival data'
df<-data.frame(id=seq(1,1000,1), event=rep(0,1000),time=floor(runif(1000,7,10)),group=floor(runif(1000,0,2)))
'set events for a few random subjects'
'only within the first 100 to check results more easily'
id_list<-c(as.numeric(floor(runif(10,1,100))))
df$event[df$id %in% id_list]<-1

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


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

'Set up surfit '
require(survminer)
KM_fit<-coxph(Surv(time , event) ~ 1 + strata(group),data= df)

What am i doing wrong?

Thanks!

Juan
  • 171
  • 1
  • 12

1 Answers1

1

It seems ggforest does not support strata (based on the code of the function, which extracts the names of the model terms: attr(model$terms, "dataClasses")[-1] and matches these to the colnames of the provided data.frame). Independent of this issue, in your provided example you tried to plot a NULL model; perhaps you want to plot this:

KM_fit <- coxph(formula=Surv(time, event) ~ group, data=df)

Instead of using strata to stratify by a second covariate, you probably have to add the second term to your model, e.g.:

df$group2 <- gl(2, k=nrow(df)/2)
KM_fit <- coxph(Surv(time , event) ~ group + group2, data= df)

That model would not be exactly the same as a stratified model, as the unstratified model would provide estimation of both factors using a single underlying hazard, while the stratification would give a hazard ratio for each strata level, but based on the output, that's probably your best bet.

user12728748
  • 8,106
  • 2
  • 9
  • 14
  • Thanks for the quick answer. Including group2 is a solution, but i wonder how to interpret such a dummy with co linearity with group.... Do you know of any good way to display hazard ratios of a stratified model? It seems all the convenient functions dont support it – Juan Jan 24 '20 at 08:17
  • is there a way to work around this without including the strata as regular covariate? There's usually a reason for stratification like the covariate not meeting the proportional hazard requirements, so including it would actually change the outcome by inducing proportionality problems – philipp.kn_98 Aug 20 '20 at 16:22
  • See [my answer](https://stackoverflow.com/a/73648569/4745348) for the work around. – Anthony Ebert Sep 08 '22 at 12:55