I was alarmed to discover that model.matrix.default() can permute columns with respect to the formula. This seems to happen with user-defined components of the formula. Thus X <- matrix(1:4, 1, 4, dimnames = list(NULL, LETTERS[1:4])) Q <- function(x) x^2 # because model.matrix() does not like, eg, A:A model.matrix(~ -1 + A + A:B + Q(C), data.frame(X)) has columns ordered A, Q(C), and A.B, not A, A.B, Q(C), as you might expect (and I certainly expected!). This appears to happen .Internal-ly. While on the subject, would it be reasonable to standardise the names of interaction terms to be A:B not A.B, to match the terms in the formula. Cheers, Jonathan. Jonathan Rougier Science Laboratories Department of Mathematical Sciences South Road University of Durham Durham DH1 3LE "[B]egin upon the precept ... that the things we see are to be weighed in the scale with what we know" (Meredith, 1879, The Egoist) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
model.matrix() (PR#285)
1 message · Jonathan Rougier