Thomas Lumley Thomas Lumley <>
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") 
[1] 1

[1] 2

[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

        if (!inherits(tt,"terms"))
                stop("need terms object")
        if (is.null(aa))
                stop("argument is not really a model matrix")
        if (attr(tt,"intercept")>0)

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
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: