r - Variable order in interaction terms -


i'm trying fit number of linear models shown below. important interaction terms sorted lexicographically. note second model missing main effect x.

x = rnorm(100) y = rnorm(100) z = x + y + rnorm(100) m1 = glm(z ~ x + y + x:y) m2 = glm(z ~ y + x:y) 

the models don't behave expected respect interaction terms:

m1:  x:y          -0.1565     0.1151  -1.360   0.1770      m2: y:x          -0.2776     0.1416  -1.961   0.0528 .  

i understand there may way use interaction() function lex.order argument can't figure out how or, indeed, whether best way go. advice?


Comments