From roger at ysidro.econ.uiuc.edu  Fri Mar 14 04:37:51 2003
From: roger at ysidro.econ.uiuc.edu (Roger Koenker)
Date: Fri Mar 14 11:32:55 2003
Subject: [Rd] [.terms
Message-ID: <Pine.SOL.4.30.0303140402160.13480-100000@ysidro.econ.uiuc.edu>

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


[Rd] [.terms
Roger Koenker