Re: [Rd] model.frame and predvars

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 05 Jun 2012 17:32:39 +0100

On 05/06/2012 16:17, Terry Therneau wrote:
> I was looking at how the model.frame method for lm works and comparing
> it to my own for coxph.
> The big difference is that I try to retain xlevels and predvars
> information for a new model frame, and lm does not.
> I use a call to model.frame in predict.coxph, which is whyI went that
> route, but never noted the difference till now (preparing for my course
> in Nashville).
>
> Could someone shed light on the rationale for non-preservation?
>

T'other way round ... it would have needed a conscious decision to preserve them: these all predate xlevels and predvars.

model.matrix.lm does make use of xlevels, and I think that explains the difference as most lm() auxiliaries use the model matrix.

And I don't see predvars used in survival:::model.frame.coxph.

> Terry T.
>
>
> Simple example
>
> > library(survival)
>
> > lfit <- lm(time ~ factor(ph.ecog) + ns(age, 3), data=lung)
> > ltemp <- model.frame(lfit, data=lung[1:2,])
> > ltemp
> time factor(ph.ecog) ns(age, 3).1 ns(age, 3).2 ns(age, 3).3
> 1 306 1 -0.1428571 0.4285714 0.7142857
> 2 455 0 0.0000000 0.0000000 0.0000000
>
> > lfit$model[1:2,]
> time factor(ph.ecog) ns(age, 3).1 ns(age, 3).2 ns(age, 3).3
> 1 306 1 0.4443546 0.3286161 0.1900511
> 2 455 0 0.5697239 0.3618440 -0.1297479
>
> > levels(ltemp[[2]])
> [1] "0" "1"
>
> > levels(lfit$model[[2]])
> [1] "0" "1" "2" "3"
>
> > cfit <- coxph(Surv(time, status) ~ factor(ph.ecog) + ns(age,3), lung)
> > model.frame(cfit, data= lung[1:2,])
> Surv(time, status) factor(ph.ecog) ns(age, 3).1 ns(age, 3).2 ns(age, 3).3
> 1 306 1 0.4443546 0.3286161 0.1900511
> 2 455 0 0.5697239 0.3618440 -0.1297479
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 05 Jun 2012 - 16:35:15 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Jun 2012 - 19:42:03 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive