[R] Is the Intercept Term always in First Position?
Viechtbauer Wolfgang (STAT)
Wolfgang.Viechtbauer at STAT.unimaas.nl
Tue Jan 5 14:30:29 CET 2010
Dear All,
I have a question about formulas and model.matrix(). If one specifies a model via a formula, the corresponding design matrix can be obtained with the model.matrix() function. For example:
x1 <- c(1,4,2,3,5)
x2 <- c(1,1,2,2,2)
myformula <- ~ x1 + factor(x2)
model.matrix(myformula)
My question is: If an intercept term is in the model (like in the example above), is it always the first column in resulting design matrix?
For example, if I add the intercept explicitly as the last term in the formula, it still ends up in the first column:
myformula <- ~ x1 + factor(x2) + 1
model.matrix(myformula)
So, is this always true or is it in principle possible that the intercept column ends up somewhere else?
Best,
--
Wolfgang Viechtbauer http://www.wvbauer.com/
Department of Methodology and Statistics Tel: +31 (0)43 388-2277
School for Public Health and Primary Care Office Location:
Maastricht University, P.O. Box 616 Room B2.01 (second floor)
6200 MD Maastricht, The Netherlands Debyeplein 1 (Randwyck)
More information about the R-help
mailing list