[R] passing a formula to coxph() along with a ...

Katki, Hormuzd (NIH/NCI) katkih at mail.nih.gov
Thu Mar 4 21:18:07 CET 2004


	Hello.  I am making a program that allows a user to enter a formula
to be used in coxph() and then does some other stuff to it, and also allows
the user to set other options within coxph().  

What is the proper way to pass a formula to a function along with a ...?  I
have a function:

func <-  function(coxformula, data = parent.frame(),...) {
# Cut to relevant part of function

coxmod <- coxph(formula=coxformula, data=dataframe,...)

resids <- residuals(coxmod,'dfbeta')
}

I use the function call:
func(Surv(failtime,cancer)~smoke,dataframe=dataset,robust=TRUE)

The coxph() evaluates properly.  But the error is in evaluating the
residuals(): 

Error in model.frame(formula = coxformula, data = dataframe, : 
	Object "coxformula" not found

When using recover(), the error upon running the residuals function is:
Error during wrapup: Object "coxformula" not found

But there are 2 times when it does work:
1.  If I do residuals.coxph(coxmod,type='martingale'), then it does work!
(But for no other residual type)
2.  If I don't include anything in the ... (i.e. I don't ask for robust=TRUE
in the call), then it works fine.

Any help is greatly appreciated.  Thank you,
Hormuzd Katki

Hormuzd Katki
Biostatistics Branch, Division of Cancer Epidemiology and Genetics
National Cancer Institute, NIH, DHHS
6120 Executive Blvd. Room 8044 MSC 7244
Rockville, MD 20852-4910
301-594-7818 (voice)
301-402-0081 (fax)
katkih at mail.nih.gov




More information about the R-help mailing list