I have a Cox regression which employs strata()
and a tt()
.
Is there any package which helps to produce a well looking, informative output of the results in table format? While ggforest()
handles tt()
it does not handle strata()
I am looking for any way to produce a suitable output other than to print summary(coxph)
. No matter whether its Latex or HTML.
The only solution so far is to build the table myself, but that does not really look appealing enough to be put into a paper....
Here is the dummy data set:
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)),
var1 = rnorm(1000, 1, 3), var2 = seq(1,1000))
'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 surfit '
require(survminer)
KM_fit<-coxph(Surv(time , event) ~ tt(var2) + strata(group)+ var1 ,data= df)
ggforest()
returns the following error:
> ggforest(KM_fit)
Error in `[.data.frame`(data, , var) : undefined columns selected
additional warning:
In .get_data(model, data = data) :
The `data` argument is not provided. Data will be extracted from model fit.
The ggforest()
function works if strata
is left out. But the model I deal with uses it.... so no solution.
The following returns a very basic table, which if i knew a bit more about lay-outing could be used, but really its not pretty!
# Prepare the columns
beta <- coef(KM_fit)
se <- sqrt(diag(KM_fit$var))
p <- 1 - pchisq((beta/se)^2, 1)
CI <- round(exp(confint(KM_fit)), 2)
# Bind columns together, and select desired rows
res <- cbind(beta, se = exp(beta), CI, p)
# Print results in a LaTeX-ready form
knitr::kable(
xtable(res)
)
Grateful for any hints and tricks!
Thanks a bunch!
also tried finalfit()
without success....