[R] Why does the order of terms in a formula translate into different models/ model matrices?

Mark Difford mark_difford at yahoo.co.uk
Fri Jan 27 19:57:08 CET 2012


On Jan 27, 2012; 6:29pm Ben Bolker wrote:

>  My best (not very well-informed) guess is that there is something going
> on with automatic dropping of terms 
>  that appear to be aliased?? and that this test is (perhaps
> unintentionally) order-dependent.

Looks to me like Ben is close to the mark here. From ?alias: "Complete
aliasing refers to effects in linear models that cannot be estimated
independently of the terms which occur earlier in the model and so have
their coefficients omitted from the fit."

> alias(m0, complete=T)
Model :
Y ~ A:B + x:A

Complete :
        (Intercept) Aa1:Bb1 Aa2:Bb1 Aa1:Bb2 Aa2:Bb2 Aa1:Bb3 Aa2:Bb3 Aa1:Bb4
Aa1:x Aa2:x
Aa2:Bb4  1          -1      -1      -1      -1      -1      -1      -1      
0     0

> alias(m1, complete=T)
Model :
Y ~ x:A + A:B

However, if you fit "proper" (or statistically sensible models), then there
is no problem reversing terms:

> logLik(m2 <- lm(Y ~ A*B + x*A, dat))
'log Lik.' -13.22186 (df=11)

> logLik(m3 <- lm(Y ~ x*A + A*B, dat))
'log Lik.' -13.22186 (df=11)

Regards, Mark Difford

-----
Mark Difford (Ph.D.)
Research Associate
Botany Department
Nelson Mandela Metropolitan University
Port Elizabeth, South Africa
--
View this message in context: http://r.789695.n4.nabble.com/Why-does-the-order-of-terms-in-a-formula-translate-into-different-models-model-matrices-tp4333408p4334385.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list