My question is about contrast coding and planned contrasts in three-way interactions for a linear mixed effects model. Sample code is provided for R and Matlab as I can work in either one, but prefer Matlab.
I have an experiment with three categorical variables:
- Group (2 levels, between subjects)
- Condition A (2 levels, within subjects)
- Condition B (3 levels, within subjects)
The design is fully crossed (i.e. each subject is exposed to each level of B within each level of A) and the groups are balanced.
+---------+------+-------+----+----+
| Subject | Item | Group | A | B |
+---------+------+-------+----+----+
| 1 | 1 | 1 | A1 | B1 |
| 1 | 2 | 1 | A1 | B2 |
| 1 | 3 | 1 | A1 | B3 |
| 1 | 4 | 1 | A2 | B1 |
| 1 | 5 | 1 | A2 | B2 |
| 1 | 6 | 1 | A2 | B3 |
| 2 | 1 | 2 | A1 | B1 |
| 2 | 2 | 2 | A1 | B2 |
| 2 | 3 | 2 | A1 | B3 |
| 2 | 4 | 2 | A2 | B1 |
| 2 | 5 | 2 | A2 | B2 |
| 2 | 6 | 2 | A2 | B3 |
+---------+------+-------+----+----+
All predictor variables are coded as factors/categorical variables and ordered according to a priori hypotheses. I want to test the three-way interaction between Group, A, and B, and would like to compare B1, B2, and B3 at each level of A for each group. I fit the following model in Matlab:
lme = fitlme(data, 'respVar ~ 1 + Group*A*B + (1|Subject) + (1|Item)', 'FitMethod', 'REML', 'DummyVarCoding', 'effects', 'CheckHessian', true);
R equivalent:
library(lme4)
contrasts(data$Group) = c(-0.5, 0.5)
contrasts(data$A) = c(-0.5, 0.5)
contrasts(data$B) <- cbind(c(1/2,0,-1/2), c(1/2, -1/2,0))
lme = lmer(respVar ~ 1 + Group*A*B + (1|Subject) + (1|Item), control=lmerControl(optCtrl=list(maxfun=100000)), data=data)
This gives me the main effects of each parameter. However, I also want to see the simple main effects (i.e. the effect of each level of B within a fixed level of A for each group). Does it make sense to re-fit the model with treatment/dummy coding (the default in R and Matlab)? Do I then need to apply a Bonferroni correction for multiple comparisons?
Also, I am specifying a random effects structure using model selection with AIC, and the model selected differs (by one term) depending on whether I use effects coding or treatment coding. (The difference in AIC between both models with either coding method is ~2). If I want to report the results of both models, which type of coding should I use for model selection?