[R] lm/model.matrix confusion (? bug)

Mark Difford mark_difford at yahoo.co.uk
Wed Dec 12 11:10:31 CET 2007


Whoops!  Sorry, forgot my session stuff, just in case ...

R version 2.6.1 RC (2007-11-22 r43520) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_South Africa.1252;LC_CTYPE=English_South
Africa.1252;LC_MONETARY=English_South
Africa.1252;LC_NUMERIC=C;LC_TIME=English_South Africa.1252

attached base packages:
[1] tcltk     splines   stats     graphics  grDevices utils     datasets 
methods   base     

other attached packages:
[1] debug_1.1.0    mvbutils_1.1.1 MASS_7.2-38    sfsmisc_1.0-0  ade4_1.4-5    
Design_2.1-1  
[7] survival_2.34  Hmisc_3.4-3   

loaded via a namespace (and not attached):
[1] cluster_1.11.9     gamlss_1.7-0       grid_2.6.1         lattice_0.17-2    
latticeExtra_0.3-1
[6] rcompgen_0.1-17    tools_2.6.1 



Mark Difford wrote:
> 
> 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-tp14292188p14292212.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list