I ran across an issue that looks like variable scoping in survfit is not acting as I would expect. Here's a minimal example:
new<-as.data.frame(list(t=1:4,d=rep(1,4),s=c(1,0,0,1))) library(survival) mine<-function(ff,df){ fit<-coxph(ff,data=df) out<-survfit(fit,df) } mine(as.formula("Surv(t,d)~s"),new) I would expect this to fit the proportional hazards regression model using formula Surv(t,d)~s, using data set new, and then calculate a separate fitted survival curve for each member of the data set. Instead I get an error Error in eval(predvars, data, env) : invalid 'envir' argument of type 'closure' The code runs without error if I modify it by copying the data set new to the local variable within the function mine before running: new<-as.data.frame(list(t=1:4,d=rep(1,4),s=c(1,0,0,1))) library(survival) mine<-function(ff,df){ fit<-coxph(ff,data=df) out<-survfit(fit,df) } df<-new mine(as.formula("Surv(t,d)~s"),new) which leads me to believe that there's some variable scoping error. Can anyone point out what I'm doing wrong? Thanks, John [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.