[R] forcing a zero level in contr.sum

Berwin A Turlach berwin at maths.uwa.edu.au
Thu Jul 8 05:06:10 CEST 2010


G'day Stephen,

On Wed, 7 Jul 2010 16:41:18 -0400
"Bond, Stephen" <Stephen.Bond at cibc.com> wrote:

> Please, do not post if you do not know the answer. People will see
> this has answers and skip.
> 
> I tried with 
> mat1=contrasts(fixw$snconv)
> mat1=mat1[,-2]
> summary(frm2sum <- glm(resp.frm ~
> C(snconv,contr=mat1)+mprime+mshape,data=fixw,family="quasibinomial"))
> 
> the unwanted level is still there. Unbelievable.

model.matrix() instead of summary() would reveal that the estimate
corresponding to "the unwanted level" is probably estimating something
quite different then what you think it estimates.

?C and look at the how.many argument, presumably you want 
            C(snconv, contr=mat1, how.many=NCOL(mat1))

To see what is going on, consider:

R> ( tmp <- gl(4,3) )
 [1] 1 1 1 2 2 2 3 3 3 4 4 4
Levels: 1 2 3 4
R> options(contrasts=c("contr.sum", "contr.poly"))
R> ( tt <- contrasts(tmp) )
  [,1] [,2] [,3]
1    1    0    0
2    0    1    0
3    0    0    1
4   -1   -1   -1
R> tt <- tt[,-2]
R> contrasts(tmp, 2) <- tt
R> tmp
 [1] 1 1 1 2 2 2 3 3 3 4 4 4
attr(,"contrasts")
  [,1] [,2]
1    1    0
2    0    0
3    0    1
4   -1   -1
Levels: 1 2 3 4
R> contrasts(tmp) <- tt
R> tmp
 [1] 1 1 1 2 2 2 3 3 3 4 4 4
attr(,"contrasts")
  [,1] [,2]       [,3]
1    1    0  0.2886751
2    0    0 -0.8660254
3    0    1  0.2886751
4   -1   -1  0.2886751
Levels: 1 2 3 4

HTH.

Cheers,

	Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)
School of Maths and Stats (M019)            +61 (8) 6488 3383 (self)
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin



More information about the R-help mailing list