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)

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to