[R] Interaction and factor ':'

Hong Ooi Hong.Ooi at iag.com.au
Thu Nov 16 06:15:43 CET 2006



Not sure if this counts as a bug or not, but I just noticed in R 2.4.0
that : and interaction are not quite equivalent. For example:

> x <- factor(letters[1:4])
> y <- factor(letters[11:14])

> x:y
[1] a:k b:l c:m d:n
Levels: a:k a:l a:m a:n b:k b:l b:m b:n c:k c:l c:m c:n d:k d:l d:m d:n

> interaction(x, y, sep=":")
[1] a:k b:l c:m d:n
Levels: a:k b:k c:k d:k a:l b:l c:l d:l a:m b:m c:m d:m a:n b:n c:n d:n

The ordering of the levels is different between the two, although
?interaction says

    f:g is the same as interaction(f,g, sep=":") when f and g are

I came across this when fitting multinom models, and the column order of
the predicted probabilities shifted around depending on whether I used
interaction or : on the LHS of the formula.

Hong Ooi
Senior Research Analyst, IAG Limited
388 George St, Sydney NSW 2000
+61 (2) 9292 1566


The information transmitted in this message and its attachme...{{dropped}}

More information about the R-help mailing list