[R] lm/model.matrix confusion (? bug)
Mark Difford
mark_difford at yahoo.co.uk
Wed Dec 12 11:05:54 CET 2007
Dear List-members,
Hopefully someone will help through my confusion:
In order to get the same coefficients as we get from the following
##
require (MASS)
summary ( lm(Gas ~ Insul/Temp - 1, data = whiteside) )
......................
we need to do the following (if we use model.matrix to specify the model)
##
summary ( lm(Gas ~ model.matrix(~ Insul/Temp - 1) - 1, data = whiteside) )
......................
That is, we need to take out "two intercepts." Is this "correct"?
Shouldn't lm check to see if an intercept has been requested as part of the
model formula?
If I do
##
summary(lm(as.formula(Gas ~ model.matrix (~ Insul/Temp-1, data=whiteside)),
data=whiteside))
.......................
we get a strange model. But the formula part of this model qualifies as a
valid formula
##
as.formula(Gas ~ model.matrix (~ Insul/Temp-1, data=whiteside))
----------------
just as if I were to write: lm(Gas ~ Insul/Temp - 1, data=whiteside)
But we know that the _correct_ formula is the following
##
as.formula(Gas ~ model.matrix (~ Insul/Temp-1, data=whiteside) -1)
-----------------
(Sorry, this is getting really long) --- So, my question/confusion comes
down to wanting to know why lm() doesn't check to see if an intercept has
been specified when the model has been specified using model.matrix.
Regards,
Mark.
--
View this message in context: http://www.nabble.com/lm-model.matrix-confusion-%28--bug%29-tp14292188p14292188.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list