attr(modelmatrix,"assign")
Thomas Lumley
Thomas Lumley <thomas@biostat.washington.edu>
Sat, 18 Apr 1998 09:51:16 -0700 (PDT)
The "assign" attribute for model matrices has mutated in S-PLUS (probably
in 3.3 or 3.4) -- the model code is obviously not subject to
enough evolutionary pressure to keep mutations down.
Now it returns a list with elements named for each model term, giving the
vector of column numbers arising from that term
> y<-1:10
> x<-1:10
> attr(model.matrix(~y+factor(x)),"assign")
$"(Intercept)":
[1] 1
$y:
[1] 2
$"factor(x)":
[1] 3 4 5 6 7 8 9 10 11
I don't think we necessarily want to change from our attr(,"assign"),
which follows Chambers & Hastie, but we may want to be able to create a
compatible version.
This can be done by the following function, which needs the terms
object as well as the model matrix
attrassign<-function(mmat,tt){
if (!inherits(tt,"terms"))
stop("need terms object")
aa<-attr(mmat,"assign")
if (is.null(aa))
stop("argument is not really a model matrix")
ll<-attr(tt,"term.labels")
if (attr(tt,"intercept")>0)
ll<-c("(Intercept)",ll)
aaa<-factor(aa,labels=ll)
split(order(aa),aaa)
}
Perhaps we should add another attribute ("S.assign") to model matrices?
Thomas Lumley
------------------------------------------------------+------
Biostatistics : "Never attribute to malice what :
Uni of Washington : can be adequately explained by :
Box 357232 : incompetence" - Hanlon's Razor :
Seattle WA 98195-7232 : :
------------------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._