I'm using coxph for adjusting by age and wt.loss.I want to draw the graph which has risk.table of each level of sex.
Here is an example code of my question.
library("survival")
# Fit cox ph
#%%%%%%%%%%%%%
res.cox <- coxph(Surv(time, status) ~ age + sex + wt.loss, data = lung)
res.cox
# Survival curves by sex after adjusting by age and wt.loss
#%%%%%%%%%%%%%%%%%%%%%%%%
# we construct a new data frame with two rows,
# one for each value of sex; the other covariates are fixed to their average values
# Create the new data
new_df <- with(lung,
data.frame(sex = c(1, 2),
age = rep(mean(age, na.rm = TRUE), 2),
wt.loss = rep(mean(wt.loss, na.rm = TRUE), 2)
)
)
new_df
# Survival curves with new data
#%%%%%%%%%%%%%%%%%%%%%%%%%%%
library(survminer)
fit <- survfit(res.cox, newdata = new_df)
ggsurvplot(fit, conf.int = TRUE, palette = "Dark2", data = lung,
censor = FALSE, surv.median.line = "hv", risk.table = TRUE)
Hi @kassambara . From the description in #67
I'm using coxph for adjusting by age and wt.loss.I want to draw the graph which has risk.table of each level of sex.
Here is an example code of my question.