In R, I can simulate data from 3 groups:
data = data.frame(Group=factor(c(rep("A",50),rep("B",50),rep("C",50))),
Y=c(rnorm(50, 50, 0.5),rnorm(50, 100, 0.5),rnorm(50, 10, 0.5)))
The default contrast matrix is
B C
A 0 0
B 1 0
C 0 1
so the intercept will correspond to the estimate for group A, and the two coefficients will compare groups B and C to group A.
The following contrast matrix
-1/3 1/2
2/3 0
-1/3 -1/2
which is obtainable using
contrasts = matrix(c(-1/3,2/3,-1/3,
1/2,0,-1/2),ncol=2,nrow=3)
compares 1) group B to the mean of groups A and C, and 2) group A to group C.
This sort of makes sense to me but then when seeing what is apparently the contrast matrix to compare 1) group A to the overall mean and 2) group B to the overall mean,
1 0
-1 1
0 -1
I get lost. I don't know mathematically what the contrast matrix is doing. Each column is a contrast; the first column has a 1 for entry A and a -1 for entry B; to me that compares group A to B, not group A to the overall mean. Can anyone explain this?