[Rd] Bugs? when dealing with contrasts

Gabor Grothendieck ggrothendieck at gmail.com
Wed Apr 21 22:43:32 CEST 2010


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)



More information about the R-devel mailing list