I want to add at-risk table and 95% confidence intervals to adjusted survival curves. Something like survival curves below (Link). I saw some relevant code here but it doesn't mention what I need.
Another question, would it be correct if I used the obtained weight variable (from iptw package) in the adjustment (as I have a column named weight in my actual dataset.
Here is my code:
library(survival);library(survminer)
data(lung);names(lung)
#fit <- coxph( Surv(time, status==2) ~ ph.karno + strata(sex), data = lung )
lung$sex <- ifelse(lung$sex == 1, "Male", "Female")
fit <- coxph(Surv(time, status) ~ ph.ecog + age +strata(sex), data = lung)
ggadjustedcurves(fit,
variable = "sex",
data = lung,
method = "average",
palette = c("#E69F00", "#56B4E9"),
size = 1.3,
legend = "right",
legend.title = expression(bold("Legend title")),
xlab = "Time",font.legend = 12) + theme(legend.text.align = 0.5)
Short Answer: Currently there is no R-Package that allows you to directly plot confounder-adjusted survival curves with confidence intervals. However there is a function called
ate
in theriskRegression
R-Package which can be used to calculate adjusted survival probability estimates at some points in time with 95% confidence intervals. If you do some coding you can definitly use that one to get what you want.Alternatively you can wait a little longer. I am currently working on an R-Package that implements various methods of confounder-adjusted survival curves (and cumulative incidence functions when there are competing risks) complete with confidence intervals, hypothesis tests, risk tables and so on.
UPDATE (09.05.2022):
The
adjustedCurves
package can now be used to obtain adjusted survival curves with confidence intervals. For your example: