[Rd] [.terms
Roger Koenker
roger at ysidro.econ.uiuc.edu
Fri Mar 14 04:37:51 MET 2003
This is a suggestion to modify the behavior of [.terms in base so that behaves as in
library(survival). In my 1.7.0 (which is admittedly a couple of weeks old):
> tt <- terms(y~qss(x)+qss(z)+w,specials="qss")
> tt
y ~ qss(x) + qss(z) + w
attr(,"variables")
list(y, qss(x), qss(z), w)
attr(,"factors")
qss(x) qss(z) w
y 0 0 0
qss(x) 1 0 0
qss(z) 0 1 0
w 0 0 1
attr(,"term.labels")
[1] "qss(x)" "qss(z)" "w"
attr(,"specials")
attr(,"specials")$qss
[1] 2 3
attr(,"order")
[1] 1 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
With survival loaded you can do something like the following:
> tmpc <- untangle.specials(tt,"qss")
> tmpc
$vars
[1] "qss(x)" "qss(z)"
$terms
[1] 1 2
> tt[-tmpc$terms]
y ~ w
attr(,"variables")
list(y, w)
attr(,"factors")
w
y 0
w 1
attr(,"term.labels")
[1] "w"
attr(,"specials")
attr(,"specials")$qss
NULL
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
This is rather handy for preprocessing additive nonparametric components of the formula
for example. Without survival loaded [ operates on the formula not the terms object to
a much less satisfactory effect.
Thanks to Thomas Lumley for pointing out to me that survival had this capability...
url www.econ.uiuc.edu Roger Koenker Dept. of Economics UCL,
email rkoenker at uiuc.edu Department of Economics Drayton House,
vox: 217-333-4558 University of Illinois 30 Gorden St,
fax: 217-244-6678 Champaign, IL 61820 London,WC1H 0AX, UK
vox: 020-7679-5838
More information about the R-devel
mailing list