Skip to content
Back to formatted view

Raw Message

Message-ID: <i2l971536df1004211343ibca0d37do8c2bd5470f43ba4f@mail.gmail.com>
Date: 2010-04-21T20:43:32Z
From: Gabor Grothendieck
Subject: Bugs? when dealing with contrasts
In-Reply-To: <4BCF5F60.7020203@gmail.com>

On Wed, Apr 21, 2010 at 4:26 PM, Peter Dalgaard <pdalgd at gmail.com> wrote:
> As for case #1, the rules are tricky in cases where interactions are
> present without main effects, but AFAICS, what you observe is
> essentially the same effect as
>
>> model.matrix(~fac-1, contrasts=list(fac="contr.sum"))
> ? fac1 fac2 fac3
> 1 ? ? 1 ? ?0 ? ?0
> 2 ? ? 1 ? ?0 ? ?0
> 3 ? ? 1 ? ?0 ? ?0
> 4 ? ? 1 ? ?0 ? ?0
> 5 ? ? 1 ? ?0 ? ?0
> 6 ? ? 0 ? ?1 ? ?0
> 7 ? ? 0 ? ?1 ? ?0
> 8 ? ? 0 ? ?1 ? ?0
> 9 ? ? 0 ? ?1 ? ?0
> 10 ? ?0 ? ?1 ? ?0
> 11 ? ?0 ? ?0 ? ?1
> 12 ? ?0 ? ?0 ? ?1
> 13 ? ?0 ? ?0 ? ?1
> 14 ? ?0 ? ?0 ? ?1
> 15 ? ?0 ? ?0 ? ?1
> attr(,"assign")
> [1] 1 1 1
> attr(,"contrasts")
> attr(,"contrasts")$fac
> [1] "contr.sum"
>
>
> I.e., that R reverts to using indicator variables when the intercept is
> absent.

Is there any nice way of getting contr.sum coding for the interaction
as opposed to the ugly code in my post that I used to force it? i.e.
cbind(1, model.matrix(~ fac)[,2:3] * scores)