I need to run cox regression model for several variables, so I want write a loop to realize it. But it doesn't work anyway. Below is my code used
names(Gen)
varlist <- names(hsb2)[8:11] ## get the variables i want to involve in loop
models <- lapply(varlist, function(x) {
coxph(substitute(Surv(Time, Status) ~ i, list(i = as.name(x))), data = Gen, ties="efron")
})
I got the error information as
errors in terms.default(formula, special, data = data) :
no terms component nor attribute
Any one has the idea of how to solve this problem or how to write the codes?