[R] To update() or not to update()?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon May 19 11:44:33 CEST 2003
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
More information about the R-help
mailing list