[R] Trouble with contrasts

Patrick E. McKnight pem at theriver.com
Sun Jan 27 06:38:21 CET 2002


Brian,

Yes, I overlooked my simplification by using con twice.  Of course, I do
not have that duplicated in real life.  The order is fixed by the
researchers who decided to identify each level with the numbers 1-4 as
specified in my matrix below (1-4 for lib1-con2, respectively).  So if I
create my matrix with the following commands:

M <- matrix(c(1,-1,0,0,0,0,1,-1,1,1,-1,-1),nrow = 4, ncol = 3)
contrasts(foo) <- M

then I get the exact contrasts I desired!  Thanks greatly for the prompt
help.  Unfortunately I limped along with MASS 2nd edition and referred
to p. 199-202 but I plan to get the latest version right away.  Your
hint gave me all I needed to get the job done.

Cheers,

Patrick



On Sat, 2002-01-26 at 00:41, Prof Brian D Ripley wrote:
> On 26 Jan 2002, Patrick E. McKnight wrote:
> 
> > Greetings,
> >
> > I have a nagging problem with contrasts and I can't seem to resolve it.
> > A factor exists with four levels (lib1, lib2, con1, con2) and when I
> > check the contrasts or set the contrasts to any of the prespecified
> > ones, I do not get the exact contrasts necessary to test the
> > theoretically relevant ones.  I need orthogonal contrasts that look just
> > like this matrix:
> >
> >        con1   con2    con3
> > lib1     1      0       1
> > lib2    -1      0       1
> > con1     0      1      -1
> > con2     0     -1      -1
> >
> > How might I change the contrast matrix for this factor and this one
> > alone?  I see in the documentation that C ought to be the ticket but I
> > can't figure out how to specify the matrix correctly.  I read in MASS or
> > S programming that the matrix can be specified but I was unable to
> > follow the example and apply the logic to my problem.
> 
> I presume that you are using con1 and con2 in two different senses in your
> rows and columns!
> 
> You need to know the order of the levels, for which it would be unusual to
> have the order you gave.  But if that is the order, and the factor is
> called` foo'
> 
> contrasts(foo) <- M
> 
> where M is the matrix you give is all that is required:  MASS p.157, last
> para.  You could also use C in the formula, but you will get less clear
> labels on your output.
> 
> I presume you do have the balance needed to make these orthogonal
> contrasts.
> 
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272860 (secr)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 
-- 
________________________________________________________________________

Cheers,

Patrick
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list