Hi Splus users,
I am presently doing some programing with S-Plus Release 3 in Windows. I
have come out with a program that runs nicely in the script. But the
problem comes when I want to make the progam into a 'function'. The
program repeatedly does a cox proportional hazard regression to the
data, dat.ma, where the observations are in the rows and the different
scenario in the columns. It works fine as a plain program but when I
start to use the syntax function, it was unable to recognize the index
'w' in the for-loop (in S-Plus output: Object "w" not found). I can't
seem to find the reason why. But when I use R to run the syntax with
function, it is able to run without the error. Below is the sample of my
program without function:
#Without the syntax function
dat.ma<-as.data.frame(t(dat.ma))
no.obs<-(ncol(dat.ma)-2)
final.out<-NULL #Store the wald test.
for(w in 1:no.obs){
sur.tmp<-coxph(Surv(dat.ma[,1],dat.ma[,2]) ~ dat.ma[,(w+2)],
dat.ma, method='breslow')
final.out<-c(final.out,sur.tmp$wald.test)
}
#This is my program with syntax function in it.
dat.ma<-as.data.frame(t(dat.ma))
rep.cox<-function(dat.ma){
no.obs<-(ncol(dat.ma)-2)
final.out<-NULL #Store the wald test.
for(w in 1:no.obs){
sur.tmp<-coxph(Surv(dat.ma[,1],dat.ma[,2]) ~
dat.ma[,(w+2)], dat.ma, method='breslow')
final.out<-c(final.out,sur.tmp$wald.test)
}
return(final.out)
}
Thanks for the help in advance.
Yours sincerely,
chuen seng
|