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

From: Mark Difford <mark_difford_at_yahoo.co.uk>
Date: Wed, 12 Dec 2007 02:10:31 -0800 (PST)

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.

______________________________________________
R-help_at_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.
Received on Wed 12 Dec 2007 - 10:18:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Dec 2007 - 11:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.