From ggrothendieck at gmail.com  Wed Apr 21 22:43:32 2010
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 21 Apr 2010 16:43:32 -0400
Subject: [Rd] Bugs? when dealing with contrasts
In-Reply-To: <4BCF5F60.7020203@gmail.com>
References: <l2u971536df1004211100q9beecbep1bceb5bbbd3b8175@mail.gmail.com> 
	<4BCF5F60.7020203@gmail.com>
Message-ID: <i2l971536df1004211343ibca0d37do8c2bd5470f43ba4f@mail.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)



[Rd] Bugs? when dealing with contrasts
Gabor Grothendieck