|Summary:||drop.terms does not preserve the predvars attribute|
|Product:||R||Reporter:||Terry Therneau <therneau>|
Description Terry Therneau 2014-10-16 14:57:07 UTC
> test <- model.frame(Employed ~ Year + poly(GNP,3) + Population, data=longley) > mterm <- terms(test) > names(attributes(mterm))  "variables" "factors" "term.labels" "order" "intercept"  "response" "class" ".Environment" "predvars" "dataClasses" > names(attributes(drop.terms(mterm,3)))  "variables" "factors" "term.labels" "order" "intercept"  "response" "class" ".Environment" Why do I care? In model.matrix.coxph any cluster() term is removed from the terms before calling model.matrix.default; this loses the predvars for terms that I keep. Ditto for strata() terms, since they could possibly generate thousands of columns that I don't need, e.g., matched case-control data. model.matrix.coxph currently has a simple workaround which could be copied. I don't know what other modeling routines may use specials in their formula that will not be a part of the model matrix.
Comment 1 Duncan Murdoch 2014-11-05 18:02:24 UTC
The docs in ?terms.object don't mention a "predvars" component, so that might be why it was dropped. However, various other functions make use of it, so it really should be kept, and should be documented. Can you write a couple of lines about what the "predvars" component is supposed to contain?
Comment 2 Duncan Murdoch 2014-11-07 19:30:11 UTC
I'll fix this for predvars and dataClasses in drop.terms and [.terms in R-devel, and eventually port to R-patched if this doesn't cause worse problems.
Comment 3 Duncan Murdoch 2014-11-13 15:22:31 UTC
Now ported to R-patched as well.