# Contrasts with interactions

I have a couple of questions about contrasts but would also appreciate any suggestions for relevant literature.

I am carrying out a GLM (binomial). There are 3 Factors (A,B,C) - A has 3 levels, B & C have 2. As main effects all factors are significant, and for factor A I can test the significance between the levels with orthogonal contrasts (-1, 0.5, 0.5)(0, -1, 1).

There is also a significant interaction between A & B and this is where I am getting stuck/confused.The interaction between A & B produces 6 treatments (A1*B1, A1*B2, A2*B1, A2*B2, A3*B1, A3*B2) Do I need to construct a matrix with 6 levels? For example...

(-1, 0.2, 0.2, 0.2, 0.2, 0.2) ( 0, -1, 0.25, 0.25, 0.25 0.25) ( 0, 0, -1, 0.33, 0.33, 0.33) ( 0, 0, 0, -1, 0.5, 0.5) ( 0, 0, 0, 0, -1, 1)

Second question - Say I am only really interested in one contrast, for example between A1*B1 and A1*B2. Is there anything stopping me doing this? I get the impression you need to create the full matrix but I have not read anywhere that it is a must? I'm using jmp and it allows me to run a single contrast I'm just not really sure if it is ok statistically?

• If you can type in the formula in JMP you don't have to create the model matrix yourself. In R to get the full interaction formula you would type : Y ~ (A + B + C)^2 (which would also give you the 3-way interaction) or Y ~ A + B + C + A:B for just the A:B interaction. you cannot just model A1:B1 and A1:B2 that would be a different factor (D = 1 if A1, 0 if not A1). Would you consider moving to R ? Feb 3, 2014 at 20:44
• I do use R, but I have to use jmp in this case. Maybe I have not explained myself properly but I have already modelled the data - fitting a maximal model then reducing to minimal model which is Y ~ A + B + C + A:B. This tells me A has a significant effect but not which level of A, it also tells me A effect depends on B or vice versa - but not which level of A. I can just plot it and compare visually but as I understand it you can do this statistically with contrasts Feb 3, 2014 at 21:51
• you should just be able to see which level of A have more of an impact in R by typing summary(myModel), the contrasts and levels will be displayed there. Feb 3, 2014 at 21:59
• summary(model) compares the levels to the intercept (one level) and not the rest. I need contrast to compare different levels Feb 3, 2014 at 22:09
• I think you are misinterpreting what you are seeing. Let me set sth. up Feb 3, 2014 at 22:28

Here is what you are describing:

Y = sample(0:1,400,replace=T)
A = sample(factor(c("A1","A2","A3")),400,replace=T)
B = sample(factor(c("B1","B2")),400,replace=T)
C = sample(factor(c("C1","C2")),400,replace=T)
mod = glm(Y ~ A + B + C + A:B, family=binomial)
summary(mod)


which gives:

glm(formula = Y ~ A + B + C + A:B, family = binomial)

Deviance Residuals:
Min      1Q  Median      3Q     Max
-1.362  -1.152   1.003   1.193   1.280

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)  0.01955    0.27106   0.072    0.943
AA2         -0.05528    0.33304  -0.166    0.868
AA3         -0.16445    0.33920  -0.485    0.628
BB2         -0.15186    0.34719  -0.437    0.662
CC2          0.07330    0.20193   0.363    0.717
AA2:BB2     -0.04942    0.49982  -0.099    0.921
AA3:BB2      0.64755    0.49179   1.317    0.188

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 554.51  on 399  degrees of freedom
Residual deviance: 551.15  on 393  degrees of freedom
AIC: 565.15


With all of the factors appropriately irrelevant (random), if some were relevant you would see them flagged ('.','*','**','***'). You can see all the factors of A, B and C. The base factors are not there because if A1=1 then A2=0 and A3=0. This link will show you how to change the contrasts in R and give you an interpretation of the summary with factors and contrasts.

• What I want to do is to set up my own contrasts rather than predetermined ones. It is my understanding (from reading The R Book second edition (Crawley) - pg 430 onwards) that this can be done for lm function but when using the glm function he seems to combine factor levels and then compare models using anova. Feb 4, 2014 at 0:11