1

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.

Community
  • 1
  • 1
user1700890
  • 7,144
  • 18
  • 87
  • 183

1 Answers1

2

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.

user2554330
  • 37,248
  • 4
  • 43
  • 90