I am looking to run several cox regression models keeping the survival function the same and putting different predictor variables and I want to save each one in a list. Additionally, I want to get a tidy output from each model in the list.
Below is an example with two predictor variables but the actual data-frame has more than 20 predictor variables.
# data frame with first 2 columns specifying time to event and event and rest as predictor variables
df <- some_data_frame
#Cox Models
cox_var1 <- coxph(Surv(time,event) ~ var1, data = df]
cox_var2 <- coxph(Surv(time,event) ~ var2, data = df]
#Tidy output of cox models
cox_summary_var1 <- broom:tidy(cox_var1, exponentiate = TRUE)
cox_summary_var2 <- broom:tidy(cox_var2, exponentiate = TRUE)
I am fairly new to purr::map()
. How can I create a list containing all the models and then a second list containing all the tidy output of the models?