Hi, Suppose I have: # Fit a base model d1.ph <- coxph(Surv(start, stop, event)~ ejec + diavol + score + smoking + beta + surg.done, data = data.frame(foo)) summary(update(d1.ph, . ~ . + td1)) summary(update(d1.ph, . ~ . + td2)) As I have many columns in my data frame, foo, called td's. e.g. td1, td2, td3, .... And I'd like to add one column each time. What is the recommended way to do this? Whether I should do what I did above, or should I do something like: td1.ph <- coxph(Surv(start, stop, event)~ ejec + diavol + score + smoking + beta + surg.done + td1, data = data.frame(foo)) td2.ph <- coxph(Surv(start, stop, event)~ ejec + diavol + score + smoking + beta + surg.done + td2, data = data.frame(foo)) I've done a system.time() on it and update() doesn't seem to be much (if at all) faster. Is there an advantage of using update() then (other than that the codes look neater)? -- Cheers, Kevin ------------------------------------------------------------------------------ /* Time is the greatest teacher, unfortunately it kills its students */ -- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki)
On Mon, 19 May 2003, Ko-Kang Kevin Wang wrote:> Suppose I have: > # Fit a base model > d1.ph <- coxph(Surv(start, stop, event)~ > ejec + diavol + score + smoking + > beta + surg.done, > data = data.frame(foo)) > > summary(update(d1.ph, . ~ . + td1)) > summary(update(d1.ph, . ~ . + td2)) > > As I have many columns in my data frame, foo, called td's. e.g. td1, td2, > td3, .... And I'd like to add one column each time. What is the > recommended way to do this? Whether I should do what I did above, or > should I do something like: > td1.ph <- coxph(Surv(start, stop, event)~ > ejec + diavol + score + smoking + > beta + surg.done + td1, > data = data.frame(foo)) > > td2.ph <- coxph(Surv(start, stop, event)~ > ejec + diavol + score + smoking + > beta + surg.done + td2, > data = data.frame(foo)) > > I've done a system.time() on it and update() doesn't seem to be much (if > at all) faster. Is there an advantage of using update() then (other than > that the codes look neater)?You are calling update.default on a coxph fit, so it is just neater. It need not be for other model-fitting classes. BTW, addterm (MASS) would automate this for you, adding all the columns one at a time and collating the results. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Hi Kevin, Here there is a possible solution Extract from the base model the response, the design matrix, (possible) strata,....Note: fit it with argument x=T and y=T o<-list() X0<-d1.ph $x Y<-d1.ph $y stra<-d1.ph $strata .... for(i in ....){ #what are the positions of "td" variables in the dataframe? X<-cbind(X0,X[,i]) o[[length(o)+1]]<- agreg.fit(X,Y,strata=stra,control=coxph.control(eps 1e-04),init=rep(0,ncol(X)), method="efron",rownames=NULL)) } o is a list with all the fitted models. agreg.fit() is faster that coxph() (that uses agreg.fit). It is something like glm() and glm.fit(). Hope this helps you. best, vito ----- Original Message ----- From: "Ko-Kang Kevin Wang" <kwan022 at stat.auckland.ac.nz> To: "R Help" <r-help at stat.math.ethz.ch> Sent: Monday, May 19, 2003 11:31 AM Subject: [R] To update() or not to update()?> Hi, > > Suppose I have: > # Fit a base model > d1.ph <- coxph(Surv(start, stop, event)~ > ejec + diavol + score + smoking + > beta + surg.done, > data = data.frame(foo)) > > summary(update(d1.ph, . ~ . + td1)) > summary(update(d1.ph, . ~ . + td2)) > > As I have many columns in my data frame, foo, called td's. e.g. td1, td2, > td3, .... And I'd like to add one column each time. What is the > recommended way to do this? Whether I should do what I did above, or > should I do something like: > td1.ph <- coxph(Surv(start, stop, event)~ > ejec + diavol + score + smoking + > beta + surg.done + td1, > data = data.frame(foo)) > > td2.ph <- coxph(Surv(start, stop, event)~ > ejec + diavol + score + smoking + > beta + surg.done + td2, > data = data.frame(foo)) > > I've done a system.time() on it and update() doesn't seem to be much (if > at all) faster. Is there an advantage of using update() then (other than > that the codes look neater)? > > > -- > Cheers, > > Kevin > > ------------------------------------------------------------------------------> /* Time is the greatest teacher, unfortunately it kills its students */ > > -- > Ko-Kang Kevin Wang > Master of Science (MSc) Student > SLC Tutor and Lab Demonstrator > Department of Statistics > University of Auckland > New Zealand > Homepage: http://www.stat.auckland.ac.nz/~kwan022 > Ph: 373-7599 > x88475 (City) > x88480 (Tamaki) > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help