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()
# please paste here the result of
devtools::session_info()
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()