I am having a little bit of trouble wrapping my head around how to specify my glmer model. My design is as follows:
- y is a binomial (Bernoulli) response variable
- x1 is a categorical (factor) predictor variable with 3 levels (repeated measures)
- x2 is a categorical (factor) predictor variable with 2 levels (independent measures)
In this experiment, each subject is exposed to every level of x1, completing 4 trials for each level (12 trials total). The order of each level is counterbalanced. For example, if A,B,C are the three levels of x1, one participant may complete 12 trials in the following order: A,A,A,A,C,C,C,C,B,B,B,B, or C,C,C,C,B,B,B,B,A,A,A,A, and so forth. Additionally, each subject is randomly assigned to a level of x2, making this an independent measures predictor variable.
We are looking to search for main effects and interactions between x1 and x2, but we need to properly specify the generalized linear mixed effect model. We have tried many approaches, but do not know which is correct. Since each subject contributes 12 responses overall in the data, we need a way to account for the fact that those 12 responses are not independent. I am thinking of treating trial as the slope of the random effect (subject) to account for that. Is this the correct approach or am I on the wrong track?
These are some that I have played with
m1 <- glmer(y ~ x1 * x2 + (1+trial|subject), family = binomial) m2 <- glmer(y ~ x1 * x2 + (1|subject), family = binomial)
To look at just the effect of x2 I tried this:
m3 <- glmer(y ~ x2 + (1+trial|subject), family = binomial)
trialto be a random effect $\endgroup$