kassambara / survminer

Survival Analysis and Visualization
https://rpkgs.datanovia.com/survminer/
487 stars 159 forks source link

surv_baseline / surv_cox_baseline #232

Open MarcinKosinski opened 7 years ago

MarcinKosinski commented 7 years ago

In this blog post - http://www.sthda.com/english/wiki/cox-proportional-hazards-model#visualizing-the-estimated-distribution-of-survival-times you present how one can Visualize the estimated distribution of survival times where you use code:

res.cox <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data =  lung)
summary(res.cox)
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

for creating a dataframe for which one would like to visualize the estimated distribution times.

What about creating a function that could extract the baseline/reference level from the fitted cox.model as a data.frame

stats::model.frame(fit)[1, -1]

that for

This data.frame could be replicated n-th times to have n rows for considered n-leveled character variable, so that one could compare estimated survival times within one variable that are based on the hazards ratio from the cox model and it's baseline.

kassambara commented 7 years ago

good suggestion!!!