1
$\begingroup$

The link (How to setup and interpret ANOVA contrasts with the car package in R?) contains some code as you can see below, which gives an example of how to set up a contrast matrix based on a 2*2 factorial design. I have been trying to set up a contrast for the interaction term based on 2*3 design (two factors a and b, while a has 2 levels of a1 and a2, and b has 3 levels of b1, b2, and b3) without success. Could someone help me out?

> d$ab <- interaction(d$a, d$b)       # creates new factor coding the 2*2 conditions
> levels(d$ab)                        # this is the order of the 4 conditions
[1] "a1.b1" "a2.b1" "a1.b2" "a2.b2"

> aovRes <- aov(y ~ ab, data=d)       # oneway ANOVA using aov() with new factor

# specify the contrasts you want to test as a matrix (see above for order of cells)
> cntrMat <- rbind("contr 01"=c(1, -1,  0,  0),  # coefficients for testing a within b1
                   "contr 02"=c(0,  0,  1, -1),  # coefficients for testing a within b2
+                  "contr 03"=c(1, -1, -1,  1))  # coefficients for interaction

Thanks a lot!

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.