Skip to content
Prev 5460 / 398502 Next

Variable names in model formula

At 10:37 PM 5/1/00 -0400, E. S. Venkatraman wrote:
You could try

covnames <- names(...)
form <- Surv(time, status) ~ dummy
for(nam in covnames) {
	form[[3]] <- as.name(nam)
	survout <- coxph(form, data = dataname)
	print(summary(survfit(survout, newdata), t0))
}
The above way is one.  A slightly more direct way would be to use some
column of the data frame on the right hand side:

for (i in 1:5) {
	survout <- coxph(Surv(time, status) ~ dataname[, i], dataname)
.....
}

There is a distinction between character strings and names.
.-.-
._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._