-
Notifications
You must be signed in to change notification settings - Fork 164
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
plotting confidence intervals for coxph using ggsurvplot #393
Comments
I have the same issue. It appears to be a bug introduced in version 0.4.4 (2019-05-21), as reverting to version 0.4.3 fixed the problem for me. |
I reverted to version 0.4.3, but this states the R version 3.6 and 3.53 are not compatible. What R source version are you using? |
I'm using R 3.6.0. Try using:
And then restart your R session. |
Hi, Thank you for pointing this issue out. A bug has been introduced by the pull request #335 In this pull request, res <- cbind(res, surv = .flat(x$surv),
std.err = ifelse(is.null(x$std.err), NA, .flat(x$std.err)),
upper = ifelse(is.null(x$upper), NA, .flat(x$upper)),
lower = ifelse(is.null(x$lower), NA, .flat(x$lower))) The documentation of ifelese states that :
So, since we are passing test values of length 1, we are getting results of length 1, leading to a uniform confidence interval for all rows. I'm fixing that |
Fixed now, thanks. Install the latest dev version as follow: devtools::install_github("kassambara/survminer", build_vignettes = FALSE) |
Hi! I installed the last package version provided in here. But I still have a flat confidence interval at the value=1. Thanks! |
Expected behavior
Using the example provided here (http://www.sthda.com/english/wiki/cox-proportional-hazards-model), I have been trying to plot two strata with confidence intervals after running a coxph. This is the example code, with data=lung added to the ggsurvplot as that was indicated as a needed fix:
data("lung")
res.cox <- coxph(Surv(time, status) ~ sex, data = lung)
res.cox
res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
summary(res.cox)
ggsurvplot(survfit(res.cox), data=lung, color = "#2E9FDF",
ggtheme = theme_minimal())
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)
ggsurvplot(fit, data=lung, conf.int = TRUE, legend.labs=c("Sex=1", "Sex=2"),
ggtheme = theme_minimal())
It should produce a nice graph like this:
Actual behavior
However, the code is producing this, with the confidence intervals all bunched up at the top:
When digging into what the survfit function is doing, it appears that the error is located there:
res.sum <- surv_summary(fit)
head(res.sum)
time n.risk n.event n.censor surv std.err upper lower strata
1 5 227 1 0 0.9949674 0.005051885 1 0.9851643 1
2 11 226 3 0 0.9799013 0.005051885 1 0.9851643 1
3 12 223 1 0 0.9748685 0.005051885 1 0.9851643 1
4 13 222 2 0 0.9647492 0.005051885 1 0.9851643 1
5 15 220 1 0 0.9596720 0.005051885 1 0.9851643 1
6 26 219 1 0 0.9546036 0.005051885 1 0.9851643 1
It then passes on a uniform confidence interval instead of one that changes by step. Is there a fix for this? I would really like to be able to graph confidence intervals for the coxph.
Steps to reproduce the problem
session_info()
The text was updated successfully, but these errors were encountered: