[R] changing model matrix restriction in lm()
rafa_moral2004 at yahoo.com.br
Wed Oct 23 15:00:15 CEST 2013
I was wondering if there was a way of changing the model matrix restriction automatically in the formula statement when fitting a model using, for example, lm().
When we do
y <- rnorm(12)
A <- gl(3, 4)
summary(lm(y ~ A))
we obtain A1=0 as a baseline and A2 and A3 as effects.
However, if I want to use A2=0 as a baseline, I can do
X <- cbind(1, model.matrix(lm(y ~ A - 1)))[,-3]
summary(lm(y ~ X))
I wonder if there is a way of specifying the restriction in the parameters directly in the formula argument instead of building the desired model matrix.
More information about the R-help