We want to run a mixed effects model for our experimental design using lme4 package in R and want to confirm if our model is specified correctly.
Our design involves two random factors (participants and stimuli) and two fixed factors – first fixed factor is ‘condition’ with 3 levels and the second fixed factor is ‘group’ with 2 levels. The condition fixed factor is a within-subjects factor and the culture fixed factor is a between-subjects factor. Stimuli are crossed across conditions and counterbalanced between participant. The code for making a full data set is below in this post.
We want to test the main effect of condition and the interaction of culture and condition. The model we specify is provided below. We have based this on a paper by Westfall and colleagues (Judd, C. M., Westfall, J., & Kenny, D. A.; 2016)and adapted the code from an app they developed. link to app: https://jakewestfall.shinyapps.io/crossedpower/),
We are adapting their code for the ‘Counterbalanced’ design as it fits most closely to our design. We also plan to contrast code the IVs, as specified in the app. Is the code below to test interaction effects specified correctly? Also, should we specify a separate model to look at main effect of condition?
model <- lmer (y ~ condition*group + (1 + condition | subj_id) + (1 + condition | scenario), data = Study1) modelrestricted <- update(model, .~. -condition:group) KRModcomp(model, modelrestricted)
Code for creating dataset:
subj <- factor(1:60) scenario <- factor(1:45) condition <- c("onlyB1", "B1M", "B1S", "B1M", "B1S", "onlyB1", "B1S", "onlyB1", "B1M") group <- c("US", "CH") y <- factor(1:5) subj_full <- rep(subj, each = 45) scenario_full <- rep(scenario, 60) condition_full <- rep(rep(condition, each=15), 20) group_full <- rep(rep(group, each=45), 30) y <- sample(y, 2700, replace = T) data_study1 <- data.frame(subj_id=subj_full, scenario=scenario_full, condition=condition_full, group=group_full, y = y)