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
integers returns 1 in the cell for corresponding variables
logicals returns FALSE in the cell for corresponding variables
characters/factors - return the reference level from fit$xlevels (the first value of each element of a list)
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.
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: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.framethat for
fit$xlevels
(the first value of each element of a list)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.