Open MarcinKosinski opened 7 years ago
When fit = survfit(res.cox, newdata)
, the output of summary(fit)
looks like this:
From this output, we have only:
time
variablen.risk
and the n.event
for the whole datasets (but not by groups)sex=1
and sex=2
(in newdata).This is why the risktable from the ggsurvplot
of an object of survfit.cox
contains only one row corresponding to the whole data set.
It seems that the risk table for groups are available only from the output of survfit.formula
() (KM).
: /
If users want to add grouped risk tables under cox adjusted survival curves, the following hack might be helpful:
require("survival")
require("survminer")
km.fit <- survfit(Surv(time, status) ~ sex, data = lung)
km.surv <- ggsurvplot(km.fit, risk.table = TRUE)
km.surv
res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
sex_df <- with(lung,
data.frame(sex = c(1, 2),
age = rep(mean(age, na.rm = TRUE), 2),
ph.ecog = c(1, 1)
)
)
sex_df
fit <- survfit(res.cox, newdata = sex_df)
cox.surv <- ggsurvplot(fit, conf.int = TRUE)
cox.surv
cox.surv$table <- km.surv$table
print(cox.surv, risk.table.height = 0.3)
Let me know, if you have another suggestion...
Two suggestions:
Improving the function ggcoxadjustedcurves()
to display risktables. This function has the argument variable
with values corresponding to groups to be plotted. In the ggcoxadjustedcurves()
code, we can do survfit(surv.obj ~ variable)
to extract and display the risktable.
Improving ggsurvplot()
to compute automatically the standard Kaplan-Meier curves to extract the risktable info, in the situation where fit = survfit.cox(res.cox, newdata)
and risktable = TRUE
.
I am planning to add risktables to ggcoxadjustedcurves() after finishing #229 If you see some easy fix for that, will be very welcomed
Yes, i'll update ggcoxadjustedcurves()
and ggsurvplot()
to handle this situation.
@kassambara great, but please wait with ggcoxadjustedcurves()
are they are being updated right now
ok, thanks.
I have the same issue. Moreover it also results in error when pval = T
as it recognizes the whole strata as 1 group although it plots the multiple groups correctly:
3: In .pvalue(fit, data = data, method = method, pval = pval, pval.coord = pval.coord, :
There are no survival curves to be compared.
This is a null model.
@bounlu Hi,have you fixed this problem? I
I am going through your great tutorial about cox proportional hazards mordel. I've found a very useful tool for visualizing the estimated survival curves that are based on the hazard estimates and baseline survival from the cox ph model.
Expected behavior
One receive survival curves (not the KM estimates this time, but the survival estimates that comes from the cox phmodel) with a risk table that is divided to 2 groups
Actual behavior
The risk.table appear to produce only one group
Additional note
If one does not specify the
risk.table
to beFALSE
then one can have thelegend.labs
to be equal to the number of groups:but when one launches the risk table, then the
legend.labs
can only have length 1I think this is due to the one group in the risk table. And when someone specifies the
legend.labs
to have vector equal to 1 you only specify the strata label in the risk set table but in the survival plot it appears that levels are added to the labels. But this isn't the intuitive behaviour. Thelegend.labs
parameter should work this way that it uses the provided character in thescale_colour_discrete
and in the risk table label. Right now forrisk.table=TRUE
one passes the risk table label (which actually shouldn't be of dimension one) withlegend.labs
and has to add thescale_colour_discrete
to customize the survival plot legendssession_info()