The following works, you need to include x=TRUE in the call to coxph.
Passing the time and status variables as additional arguments is a matter of
personal preference.
f.coxph.zph<-function(x, timeVar, statusVar)
{
cox.fit <- coxph(Surv(timeVar, statusVar) ~ x, na.action na.exclude, method
= "breslow", x=TRUE)
fit.zph<-cox.zph(cox.fit)
fit.zph$table[,3]
}
time.cox <- ovarian$futime
status.cox <- ovarian$fustat
apply(ovarian[,-(1:2)],2, f.coxph.zph, timeVar = time.cox, statusVar status.cox)
--Matt
-----Original Message-----
From: s-news-owner at lists.biostat.wustl.edu
[mailto:s-news-owner at lists.biostat.wustl.edu]On Behalf Of array chip
Sent: Tuesday, November 09, 2004 16:50 PM
To: s-news at lists.biostat.wustl.edu; r-help at stat.math.ethz.ch
Subject: [S] worked in R, but not in S-Plus
Hi,
I wrote a function that worked well in R, but not in
S-Plus, can anyone suggest a solution?
> f.coxph.zph<-function(x)
{
cox.fit <- coxph(Surv(time.cox, status.cox) ~ x,
na.action = na.exclude, method = "breslow")
fit.zph<-cox.zph(cox.fit,transform='log')
fit.zph$table[,3]
}
yyy is my data frame that contains survial time,
censor status and predictor variables.
> time.cox<-yyy$time
> status.cox<-yyy$status
> apply(yyy[,-(1:2)],2,f.coxph.zph)
When run in S-Plus, it gave the following error
message:
Problem in model.frame.coxph(fit): Object "x" not
found
If I remove the 2nd and 3rd lines inside the function,
it worked, so definitely something is wrong in passing
the coxph object into the cox.zph().
Thanks
__________________________________
--------------------------------------------------------------------
This message was distributed by s-news at lists.biostat.wustl.edu. To
...(s-news.. clipped)...