[Rd] model.frame and predvars

From: Terry Therneau <therneau_at_mayo.edu>
Date: Tue, 05 Jun 2012 10:17:58 -0500


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 why I 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?

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 Received on Tue 05 Jun 2012 - 15:24:35 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 - 17:52:22 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