To partly answer my own question: It wasn't that hard to hack the
result of model.matrix() to remove the intercept,
remove.intercept <- function(x) {
if (colnames(x)[1] == "(Intercept)") {
x <- x[,-1]
attr(x, "assign") <- attr(x, "assign")[-1]
}
x
}
However, the model frame and therefore the model terms stored in the
object are wrong, still including the intercept:
On 1/29/2013 8:44 AM, Michael Friendly wrote:
I'm trying to write a formula method for canonical correlation analysis,
that could be called similarly to lm() for
a multivariate response:
cancor(cbind(y1,y2,y3) ~ x1+x2+x3+x4, data=, ...)
or perhaps more naturally,
cancor(cbind(y1,y2,y3) ~ cbind(x1,x2,x3,x4), data=, ...)
I've adapted the code from lm() to my case, but in this situation, it
doesn't make sense to
include an intercept, since X & Y are mean centered by default in the
computation.
In the code below, I can't see where the intercept gets included in the
model matrix and therefore
how to suppress it. There is a test case at the end, showing that the
method fails when called
normally, but works if I explicitly use -1 in the formula. I could hack
the result of model.matrix(),
but maybe there's an easier way?