In addition, there is a formula method for data.frame that
assumes the first column is the dependent variable.
> z <- data.frame(X1=1:6,X2=letters[1:3],Y=log(1:6))
> formula(z)
X1 ~ X2 + Y
> colnames(model.matrix(formula(z), z))
[1] "(Intercept)" "X2b" "X2c" "Y"
Spencer's requ
Dear Spencer,
I don't think that the problem of "converting a data frame into a model matrix"
is well-defined, because there isn't a unique mapping from one to the other.
In your example, you build the model matrix for the additive formula ~ a + b
from the data frame matrix containing a and b