[R-lang] contrast coding
Bob Slevc
slevc at rice.edu
Fri Sep 5 13:27:50 PDT 2008
Hi there R-language-gurus,
I have what I think is a simple question – maybe even a stupid
question (and there are too stupid questions) – that's related to
recent discussions on this list. Imagine, if you will, that I have a
full-factorial design, and want to set up a set of orthogonal
contrasts rather than using R's default dummy coding. For a simple
2x2 design, I want something like this, where contrasts 1 and 2 are
the main effects for A and B, and contrast 3 is the interaction:
a1 a1 a2 a2
b1 b2 b1 b2
contrast1 1 1 -1 -1
contrast2 1 -1 1 -1
contrast3 1 -1 -1 1
I haven't found any contrast function (e.g., contr.poly / contr.sum /
etc.) that'll automatically create a matrix for this kind of
contrast, but can I just specify the individual factor contrasts and
assume that R will just multiply them to give nice orthogonal
interaction contrasts? For example, if my factors are called A and
B, and I say:
contrasts(datafile$A) <- c(1,-1)
contrasts(datafile$B) <- c(1,-1)
and then run a model (on log(RTs) apparently):
model <- lmer(log(RT) ~ A*B + (1|subj) + (1|item), data=datafile)
Then am I set? I'm a little unsure, partially because it gives me
slightly different results than the default dummy coding does (though
it does seem to be orthogonal as the correlations between fixed
effects are all zero...)
Thanks much,
Bob
---
L. Robert (Bob) Slevc, Ph.D.
Rice University, Dept. of Psychology • 6100 Main Street • Houston, TX
77005
http://www.ruf.rice.edu/~slevc/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://pidgin.ucsd.edu/pipermail/r-lang/attachments/20080905/0545c908/attachment.htm
More information about the R-lang
mailing list