[R] How to get interction terms first in a model

BXC (Bendix Carstensen) bxc at steno.dk
Thu Feb 17 14:39:53 CET 2005


Consider the following two specifications of a model:

library( splines )
x <- 1:100
y <- rnorm( 100 )
w <- rep( 1, 100 )
A <- factor( sample( 1:2, 100, replace=T ) )
B <- factor( sample( letters[1:4], 100, replace=T ) )
summary( lm( y ~ ns( x, knots=c(30, 50, 70 ), intercept=T ):A - 1 + B )
)
summary( lm( y ~ ns( x, knots=c(30, 50, 70 ), intercept=T ):A - 1 + B:w
) )

The interaction with the constant variable w is how I got to have the
two spline terms as "proper" intercept terms.

Is there another way to do this, or is it a featur of the model formulae
that lower order terms appear before higher order terms regardless of
the
order they are specified in the model?

Bendix Carstensen
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
bxc at steno.dk
www.biostat.ku.dk/~bxc




More information about the R-help mailing list