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