Reputation: 7730
I am building survival model and my code looks something like this:
library('survival')
my.model <- coxhp(Surv(time, event) ~ var_1+var_2+var_3+var_4+var_5, data =df)
The problem is that I have too many variables and set of variables is always changing, I wonder if it would be possible to create list of variables and feed it into model. Something like this:
my.var <- c(var_1+var_2+var_3+var_4+var_5)
my.model <- coxhp(Surv(time, event) ~ my.var, data =df)
I found similar post for linear model linear model solution, but do not know how adapt it to coxph.
Upvotes: 1
Views: 134
Reputation: 44897
You can use "." to mean "all variables not used already". So for your example,
my.model <- coxph(Surv(time, event) ~ ., data = df[,c("time", "event", my.var)])
should work.
Upvotes: 2