<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>Hi there R-language-gurus,</div><div><br></div><div>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:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>a1<span class="Apple-tab-span" style="white-space:pre">        </span>a1<span class="Apple-tab-span" style="white-space:pre">        </span>a2<span class="Apple-tab-span" style="white-space:pre">        </span>a2<br></div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>b1<span class="Apple-tab-span" style="white-space:pre">        </span>b2<span class="Apple-tab-span" style="white-space:pre">        </span>b1<span class="Apple-tab-span" style="white-space:pre">        </span>b2<br></div><div>contrast1<span class="Apple-tab-span" style="white-space:pre">        </span>1<span class="Apple-tab-span" style="white-space:pre">        </span>1<span class="Apple-tab-span" style="white-space:pre">        </span>-1<span class="Apple-tab-span" style="white-space:pre">        </span>-1</div><div>contrast2<span class="Apple-tab-span" style="white-space:pre">        </span>1<span class="Apple-tab-span" style="white-space:pre">        </span>-1<span class="Apple-tab-span" style="white-space:pre">        </span>1<span class="Apple-tab-span" style="white-space:pre">        </span>-1</div><div>contrast3<span class="Apple-tab-span" style="white-space:pre">        </span>1<span class="Apple-tab-span" style="white-space:pre">        </span>-1<span class="Apple-tab-span" style="white-space:pre">        </span>-1<span class="Apple-tab-span" style="white-space:pre">        </span>1</div><div><br></div><div>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:</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">contrasts</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">(</font><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">datafile</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">$</font><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">A</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">) <- </font><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">c</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">(</font><font face="Monaco" size="3" color="#145119" style="font: normal normal normal 11px/normal Monaco; color: rgb(20, 81, 25); ">1</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">,-</font><font face="Monaco" size="3" color="#145119" style="font: normal normal normal 11px/normal Monaco; color: rgb(20, 81, 25); ">1</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">)</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">contrasts</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">(</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); "><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; "><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">datafile</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">$</font><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">B</font></span>) <- </font><font face="Monaco" size="3" style="font: normal normal normal 11px/normal Monaco; ">c</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">(</font><font face="Monaco" size="3" color="#145119" style="font: normal normal normal 11px/normal Monaco; color: rgb(20, 81, 25); ">1</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">,-</font><font face="Monaco" size="3" color="#145119" style="font: normal normal normal 11px/normal Monaco; color: rgb(20, 81, 25); ">1</font><font face="Monaco" size="3" color="#001a99" style="font: normal normal normal 11px/normal Monaco; color: rgb(0, 26, 153); ">)</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div></div><div>and then run a model (on log(RTs) apparently):</div><div><br></div><div><font class="Apple-style-span" face="Monaco" size="3"><span class="Apple-style-span" style="font-size: 11px;">model <- lmer(log(RT) ~ A*B + (1|subj) + (1|item), data=datafile)</span></font></div><div><br></div><div>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...)</div><div><br></div><div>Thanks much,</div><div>Bob</div><br><div> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div>---</div><div>L. Robert (Bob) Slevc, Ph.D.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Rice University, Dept. of Psychology • 6100 Main Street • Houston, TX 77005</div><div><a href="http://www.ruf.rice.edu/~slevc/">http://www.ruf.rice.edu/~slevc/</a></div></span></span></div><br></body></html>