An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20110718/1b41164c/attachment.pl>
Confusion about contrasts
2 messages · Marius, Reinhold Kliegl
Your solution is ok. Basically, for the set of prime contrasts you want to use you need to take the generalized inverse (see, e.g., Venables & Ripley, 2002, MASS, section 6.2, p. 144-150). That's what make.contrasts() does. Alternatively, you can use: ################ library(MASS) # for ginv() and fractions() # target contrast contrasts(trimmedwords$target) <- contr.sdif(2) # avoid treatment contrast for target factor # prime contrasts (primeconts<-cbind(c(-1,0,1,0), c(0,-1,1,0), c(0,0,-1,1))) (cmat1 <- fractions(ginv(t(primeconts)))) contrasts(trimmedwords$prime) <- cmat1 priming.model<-lmer(react~target*prime+(1|subject)+(1|item),data=trimmedwords) # alternative contrasts (altconts <- cbind(c(-1,0,1,0), c(0,-1,1,0), c(-1,1,0,0))) (cmat2 <- fractions(ginv(t(altconts)))) contrasts(trimmedwords$prime) <- cmat2 priming.model<-lmer(react~target*prime+(1|subject)+(1|item),data=trimmedwords) ################# Obviously, you don't need to do this if cmat == ginv(t(cmat))--as is the case for treatment and a few other types of contrasts. Also, this is nothing special about lmer(), but applies to all linear models using a model matrix in R. Reinhold Kliegl
On Mon, Jul 18, 2011 at 1:41 AM, Marius <marius.mather at gmail.com> wrote:
Dear all,
I'm struggling to understand how lmer handles contrasts. I have a lexical
decision experiment that I'm trying to analyse, where regular or irregular
verbs (the targets) are preceded by four different kinds of prime, making it
a (2x4) within-subjects design. I'm pretty sure I have the basic model
specification right, i.e. something like this:
priming.model<-lmer(react~target*prime+(1|subject)+(1|item),data=trimmedwords)
The contrasts I would be most interested in are comparing the first prime
condition to the third, and the second to the third. Initially I was
planning to set the contrasts for the prime factor like this (I realise
these are not orthogonal, is this a problem?):
primeconts<-cbind(c(-1,0,1,0),c(0,-1,1,0),c(0,0,-1,1))
colnames(primeconts)<-c("1v3","2v3","3v4")
primeconts
? ? 1v3 2v3 3v4
[1,] ?-1 ? 0 ? 0
[2,] ? 0 ?-1 ? 0
[3,] ? 1 ? 1 ?-1
[4,] ? 0 ? 0 ? 1
However, I've been told by one of the other researchers here that you need
the contrasts in the form given by make.contrasts() in the gmodels package,
which creates contrasts "in the form that R requires". I'm having trouble
finding out exactly what this command does in the package documentation, and
I'm a little wary of using something I don't understand. For the set of
contrasts above, make.contrasts() returns:
? ? ?C1 ? ?C2 ? ?C3
V1 -0.75 ?0.25 -0.25
V2 ?0.25 -0.75 -0.25
V3 ?0.25 ?0.25 -0.25
V4 ?0.25 ?0.25 ?0.75
but when I've used a different set of contrasts (albeit possibly not the
most sensible ones), it returns something a lot less understandable, hence
my hesitation:
make.contrasts(rbind(c(-1,0,1,0),c(0,-1,1,0),c(-1,1,0,0)))
? ? ? ? ? ? ?C1 ? ? ? ? C2 ? ? ? ? ? ?C3
V1 -3.333333e-01 ?0.0000000 -3.333333e-01
V2 ?3.148450e-17 -0.3333333 ?3.333333e-01
V3 ?3.333333e-01 ?0.3333333 -2.775558e-17
V4 ?0.000000e+00 ?0.0000000 ?0.000000e+00
The first set of contrasts given by make.contrasts() looks like what I'm
familiar with from linear regression, where you set the coefficients for the
groups in the contrast so that their mean is 0 and the difference between
them is 1, so that the intercept in the regression output represents the
overall mean, and the unstandardized beta for the contrast effect gives you
the difference between the groups (i.e. the contrast estimate) directly.
Can anyone shed some light on the best way to code the contrasts? If it is
the make.contrasts() method, I would appreciate a brief explanation on what
that function actually does, in terms of the properties of the matrix it
returns.
Thanks in advance,
Marius
? ? ? ?[[alternative HTML version deleted]]
_______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models