'Add at risk table and 95% confidence intervals to adjusted survival curves using survminer package in r
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)
Solution 1:[1]
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 the riskRegression
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:
library(survival)
library(devtools)
# install adjustedCurves from github, load it
devtools::install_github("/RobinDenz1/adjustedCurves")
library(adjustedCurves)
# fit required model
lung$sex <- as.factor(ifelse(lung$sex == 1, "Male", "Female"))
lung$status <- lung$status - 1
fit <- coxph(Surv(time, status) ~ ph.ecog + age + strata(sex), data=lung,
x=TRUE)
# calculate and plot curves
adj <- adjustedsurv(data=lung, variable="sex", ev_time="time",
event="status", method="direct",
outcome_model=fit, conf_int=TRUE)
plot(adj, conf_int=TRUE)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |