s-news
[Top] [All Lists]

Re: [S] Summary: survfit + coxph

To: s-news@wubios.wustl.edu
Subject: Re: [S] Summary: survfit + coxph
From: "Paul Y. Peng" <peng@stat.ualberta.ca>
Date: Mon, 25 May 1998 20:08:22 -0600 (MDT)
Sender: owner-s-news@wubios.wustl.edu
Thanks to you for your responses. Professor Brian Ripley provided an
answer. He actually described the situation where I experienced the
problem, which is slightly more complicated than what I said in the
message. Suppose I have a function

myfun <- function(data) {
        survfit(coxph(Surv(time, cens) ~ group, data=data)
}

Then

> myfun(mydata)

doesn't work. Modify the function as suggested by Brian

myfun <- function(data) {
        dd <- deparse(substitute(data))
        call <- paste("survfit(coxph(Surv(time, cens) ~ group, data=", dd, "))")
        eval(parse(text=call), sys.parent())
}

then it works. However, if I have another function calling it

myanother <- function(data) {
        myfun(data)
}

then

> myanother(mydata)

won't work again. So in this case, a "better" way seems to be the
first method suggested in Brian's message: assign the mydata to frame 1.
Although it solves my problem, it has an undesirable side-effect:
mydata is now visible to all nested functions in the call.

I understand that all of these problems come from eval(Call) in
model.frame.coxph. Apparently adding sys.parent() to eval(Call) will
not solve the problem. I wonder whether there is a neat fix to
model.frame.coxph (or other similar functions) so that I don't
need to worry about the frames in such a straightforward function
call.

BTW, Patrick Burns's S Poetry is very helpful resource. I did search
it for a quick solution when I got this problem, but I went to a wrong
place.

Regards,

Paul.
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [S] Summary: survfit + coxph, Paul Y. Peng <=