Skip to content

To update() or not to update()?

3 messages · Ko-Kang Kevin Wang, Brian Ripley, vito muggeo

#
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)?
#
On Mon, 19 May 2003, Ko-Kang Kevin Wang wrote:

            
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.
#
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()?
----