# [R] interaction contrasts

David Winsemius dwinsemius at comcast.net
Fri Oct 15 17:31:40 CEST 2010

```Should you need to do it again, you may want to look at the relevel
function. I suppose that would meet the definition of some versions of
"on the fly" but once I have a model, rerunning with a different
factor leveling is generally pretty painless.

--
David.

On Oct 15, 2010, at 9:09 AM, Kay Cichini wrote:

>
> ..by some (extensive) trial and error reordering the contrast matrix
> and the
> reference level
> i figured it out myself -
> for anyone who might find this helpful searching for a similar
> contrast in
> the future:
> this should be the right one:
>
> c2<-rbind("fac2-effect in A"=c(0,1,0,0,0,0,0,0),
>          "fac2-effect in B"=c(0,1,0,0,0,1,0,0),
>          "fac2-effect in C"=c(0,1,0,0,0,0,1,0),
>          "fac2-effect in D"=c(0,1,0,0,0,0,0,1),
> 	    "fac2-effect, A*B"=c(0,0,0,0,0,1,0,0),
>          "fac2-effect, A*C"=c(0,0,0,0,0,0,1,0),
>          "fac2-effect, A*D"=c(0,0,0,0,0,0,0,1),
> 	    "fac2-effect, B*C"=c(0,0,0,0,0,-1,1,0),
> 	    "fac2-effect, B*D"=c(0,0,0,0,0,-1,0,1),
> 	    "fac2-effect, C*D"=c(0,0,0,0,0,0,-1,1))
>
> summary(glht(mod,c2))
>
>
> Kay Cichini wrote:
>>
>> hello,
>>
>> i was shortly asking the list for help with some interaction
>> contrasts
>> (see below) for which
>> i had to change the reference level of the model "on the fly" (i
>> post that this is possible in
>> multcomp).
>>
>> if someone has a clue how this is coded in multcomp; glht() -
>> me there.
>>
>> yours,
>> kay
>>
>>
>> Kay Cichini wrote:
>>>
>>> hello list,
>>>
>>> i'd very much appreciate help with setting up the
>>> contrast for a 2-factorial crossed design.
>>>
>>> here is a toy example:
>>>
>>> library(multcomp)
>>>
>>> dat<-data.frame(fac1=gl(4,8,labels=LETTERS[1:4]),
>>>                fac2=rep(c("I","II"),16),y=rnorm(32,1,1))
>>>
>>> mod<-lm(y~fac1*fac2,data=dat)
>>>
>>> ## the contrasts i'm interressted in:
>>>
>>> c1<-rbind("fac2-effect in A"=c(0,1,0,0,0,0,0,0),
>>>          "fac2-effect in B"=c(0,1,0,0,0,1,0,0),
>>>          "fac2-effect in C"=c(0,1,0,0,0,0,1,0),
>>>          "fac2-effect in D"=c(0,1,0,0,0,0,0,1),
>>> 	    "fac2-effect, A*B"=c(0,0,0,0,0,1,0,0),
>>>          "fac2-effect, A*C"=c(0,0,0,0,0,0,1,0),
>>>          "fac2-effect, A*D"=c(0,0,0,0,0,0,0,1))
>>>
>>> summary(glht(mod,c1))
>>>
>>> ## now i want to add the remaining combinations
>>> ## "fac2, B*C"
>>> ## "fac2, B*D"
>>> ## "fac2, C*D"
>>> ## to the simultanous tests to see whether the effects
>>> ## of fac2 within the levels of fac1 differ between
>>> ## each combination of the levels of fac1, or not ??
>>>
>>>
>>> yours,
>>> kay
>>>
>>>
>>>
>>
>>
>
>
> -----
> ------------------------
> Kay Cichini
> Institute of Botany
> Univ. of Innsbruck
> ------------------------
>
> --
> View this message in context: http://r.789695.n4.nabble.com/interaction-contrasts-tp2993845p2996987.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help