I've tried to custom code contrasts in emmeans to understand the effect of a combined treatment variable (combination of factors, Dose_Climate). I am not sure the contrast of contrasts I've coded is properly capturing the same thing as a regular interaction effect (which is what I want) because I have unexpected results from the contrast of contrasts.
The variable was combined because models with the interaction Dose*Climate had high vifs and thus I was worried about type-ii error (p-values for interaction effect didn't make sense when looking at the data).
#data
Row <- c("A","A","A","A","A","A","B","B","B","B","B","B","C","C","C","C","C","C","D","D","D","D","D","D","E","E","E","E","E","E","F","F","F","F","F","F")
Dose_Climate <-c("H_1Normal","H_Climate","2L_1Normal","2L_Climate","1K_1Normal","1K_Climate","1K_1Normal","H_Climate","H_1Normal",
"2L_Climate","2L_1Normal","1K_Climate","2L_Climate","1K_1Normal","1K_Climate","H_1Normal","H_Climate","2L_1Normal",
"H_1Normal","2L_Climate","2L_1Normal","1K_Climate","1K_1Normal","H_Climate","1K_1Normal","H_1Normal","H_Climate",
"2L_1Normal","2L_Climate","1K_Climate","2L_Climate","H_Climate","H_1Normal","2L_1Normal","1K_Climate","1K_1Normal")
Pest <- c(0,3,2,2,12,4,5,4,0,0,5,7,0,8,3,1,2,1,0,1,1,4,9,2,6,1,3,0,7,10,2,1,1,2,6,5)
df <- data.frame(Row, Dose_Climate, Pest)
#model
m1 <- bglmer(Pest~Dose_Climate+(1|Row), data=df,
family = poisson) #using blme because of singularity issues
#custom contrast set to answer research questions
emm <- emmeans(m1, ~Dose_Climate)
H_Climate = c(0,0,0,0,0,1) # translating the order into a matrix
H_Normal = c(0,0,0,0,1,0)
K_Climate = c(0,1,0,0,0,0)
K_Normal = c(1,0,0,0,0,0)
L_Climate = c(0,0,0,1,0,0)
L_Normal = c(0,0,1,0,0,0)
c1 <- contrast(emm, method=list("K_Normal-L_Normal"=K_Normal-L_Normal,
"K_Normal-H_Normal"=K_Normal-H_Normal,
"L_Normal-H_Normal"=L_Normal-H_Normal,
"K_Climate-L_Climate"=K_Climate-L_Climate,
"K_Climate-H_Climate"=K_Climate-H_Climate,
"L_Climate-H_Climate"=L_Climate-H_Climate),
adjust="Holm")
c1
If you run the code, from the set we see that the first three contrasts are similar to the second three in that K vs L is significant and K vs H is significant but L vs H is not. Here I would not expect a significant interactions contrast because the relationships between the individual levels are similar within the "Normal" set and the "Climate" set. But..
Normal= c(1,1,1,0,0,0) #coding position of Normal in c1 grid object
Climate= c(0,0,0,1,1,1) #coding position of Climate in c1 grid object
c2 <- contrast(c1, method=list("Normal-Climate"=Normal-Climate))
c2
The contrast of the contrasts is significant. This wasn't expected (and other models of mine have also shown unexpected contrast of contrasts behavior with this coding). Am I properly representing an interaction effect with this coding? As I understand it, my code takes an "average difference" so to speak over the first three contrasts and compares it with the "average difference" from the second three contrasts. I am just not sure if this is comparable to testing for an interaction, and if not, what the proper coding for it would be. Thanks in advance.
Dose*Climate
in the model, define emmeansemm <- emmeans(model, ~Dose*Climate)
, thencontrast(emm, interaction = "consec")
. Using stuff that's already been set up saves you from making errors. $\endgroup$options(contrasts = c("contr.helmert", "contr.poly")
which will improve the numerical conditioning of the regression equation. (That change of factor coding has no effect on theemmeans()
results.) $\endgroup$vignette("interactions", "emmeans")
which gives discussions and examples relating to interactions. $\endgroup$